c++输入n个数,求最大值和最小值

#include “stdafx.h”
#include
using namespace std;
int main()
{
int n,min,max,k;
cin >> n;
cout << “输入” << n << “个数,求最大值和最小值” << endl;
cin >> k;
max = min = k;
for (int i = 0; i < n-1; i++)
{
cin >> k;
if (max < k)
max = k;
if (min > k)
min = k;
}
cout << “最大值为:” << max << endl;
cout << “最小值为:” << min << endl;
return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43210805/article/details/82791678