如题所述
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "请输入一个数字(1~20):";
cin >> n;
if ( n < 1 || n > 20 ) {
cout << "输入有误!" << endl;
return 1;
}
int a[20];
int max;
cout << "请输入这" << n << "个数:" << endl;
cin >> a[0];
max = a[0];
for ( int i = 1; i < n; ++i ) {
cin >> a[i];
if ( max < a[i] )
max = a[i];
}
cout << "这些数字中的最大数是: " << max << endl;
return 0;
}
using namespace std;
int main()
{
int n;
cout << "请输入一个数字(1~20):";
cin >> n;
if ( n < 1 || n > 20 ) {
cout << "输入有误!" << endl;
return 1;
}
int a[20];
int max;
cout << "请输入这" << n << "个数:" << endl;
cin >> a[0];
max = a[0];
for ( int i = 1; i < n; ++i ) {
cin >> a[i];
if ( max < a[i] )
max = a[i];
}
cout << "这些数字中的最大数是: " << max << endl;
return 0;
}
温馨提示:答案为网友推荐,仅供参考