概述
题目描述
Write a program which reads a sequence of n integers ai(i=1,2,…n), and prints the minimum value, maximum value and sum of the sequence.
输入
In the first line, an integer n is given. In the next line, n integers ai are given in a line.
输出
Print the minimum value, maximum value and sum in a line. Put a single space between the values.
注: 还应该比较max或min与新赋值i的大小
题解
#include<bits/stdc++.h>
using namespace std;
int main() {
int a, n, i, max, min, sum, t;
scanf("%d %d", &n, &a);
sum = a;
max = a; min = a;
while (n > 1) {
scanf("%d", &i);
sum = sum + i;
if (a <= i) {
if (max < i) {
max = i;
}
if (min > a) {
min = a;
}
}
else {
if (max < a) {
max = a;
}
if (min > i) {
min = i;
}
}
n = n - 1;
}
cout << min << " " << max << " " << sum << endl;
return 0;
}
最后
以上就是刻苦鸡为你收集整理的Computation – Min, Max and Sum的全部内容,希望文章能够帮你解决Computation – Min, Max and Sum所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复