【发布时间】:2019-04-05 11:47:36
【问题描述】:
我对这段代码如何流动感到困惑,尤其是在输入一组整数之后。 例如如何存储输入,然后进行比较以找到集合中的最大值?
#include <iostream>
using namespace std;
int main()
{
int n, num, max, k=1;
cout << " Enter how many integers " << endl;
cin >> n;
cout << " enter " << n << " integers: "; // where input be stored
cin >> max; // this will input the last number right?
// if i entered 50 55 60 where they will be stored dont i need to store them in in 3 seprate places
while (k<n)
{
cin >> num; // what is the function of this line? from where the input will be
if (num > max)
max = num;
k++;
}
cout << " largest integer is :" << max << endl;
return 0;
}
【问题讨论】:
标签: c++ loops while-loop