【问题描述】输入一些整数,求出它们的最小值、最大值和平均值(保留3位小数)。
【输入形式】
一批用空格隔开的整数,回车后,再按ctrl+Z结束。(注ctrl+Z代表标准输入文件结束)
【输出形式】
最小数 最大数 平均数(用空格隔开)
【样例输入】
2 8 3 5 1 7 3 6
【样例输出】
1 8 4.375
【样例说明】
请查阅有关scanf()函数的返回值的用途。
while(scanf("%d",&x)!=EOF){ /scanf()函数读入数据时遇到了文件结束则返回EOF/
处理x;
}
【评分标准】
#include<stdio.h>
#include<math.h>
using namespace std;
int main(){
int x,n=0,s=0,a,b;
while(scanf("%d",&x)!=EOF){
s+=x;
n++;
if(n==1){
a=x;//a保存最小值
b=x;//b保存最大值
}else {
if(x<a) a=x;
if(x>b) b=x;
}
}
printf("%d %d %.3lf",a,b,s*1.0/n);
return 0;
}