【编程实现】
做统计。
输入 10 个正整数,以空格分隔。依次输出其中的最大值、最小值以及平均值,以逗号分隔。
【样例输入】
1 2 3 4 5 6 7 8 9 10
【样例输出】
10, 1, 5.5
//【参考答案】
#include<iostream>
#include<cstring>
using namespace std;
int main(){
int min,max,sum=0,temp;
cin>>temp;
sum=min=max=temp;
for(int i=0;i<9;i++){
cin>>temp;
min=min<temp?min:temp;
max=max>temp?max:temp;
sum+=temp;
}
cout<<max<<","<<min<<","<<sum/10.0;
return 0;
}

该程序使用C++实现,接收用户输入的10个正整数,然后计算并输出这些数中的最大值、最小值以及它们的平均值。样例输入为1到10的数字,输出结果为10,1,5.5。此程序展示了基础的数值统计计算和输入输出操作。
1516

被折叠的 条评论
为什么被折叠?



