输入N个数,求这N个数的和并求出最大值和最小值
程序员文章站
2023-12-27 18:16:21
...
#include<iostream>
#define INF 0x3f3f3f3f
using namespace std;
int main()
{
int n;
cin >> n;
int sum =0;
int Max = -INF;
int Min = INF;
while (n>0)
{
int v;
cin >> v;
if(v > Max)
Max = v;
if(v < Min)
Min = v;
sum = sum + v;
n = n - 1;
}
cout <<sum <<endl;
cout << Max << endl;
cout << Min << endl;
return 0;
}