p28
数据统计
#define LOCAL
#include<stdio.h>
#define INF 1000000000
int main()
{
#ifdef LOCAL
freopen("datain.txt","r",stdin); //重定向版
freopen("dataout.txt","w",stdout);
#endif
int x,n=0,min=INF,max=-INF,s=0;
while(scanf("%d",&x)==1)
{s+=x;
if(x<min) min=x;
if(x>max) max=x;
n++;
}
printf("%d %d %.3f\n",min,max,(double)s/n);
}
#include<stdio.h>
#define INF 1000000000
int main()
{
FILE*fin,*fout; //fopen版
fin=fopen("datain.txt","r");
fout=fopen("dataout.txt","w");
int x,n=0,min=INF,max=-INF,s=0;
while(fscanf(fin,"%d",&x)==1) //注意修改fscanf
{s+=x;
if(x<min) min=x;
if(x>max) max=x;
n++;
}
fprintf(fout,"%d %d %.3f\n",min,max,(double)s/n); //注意修改fprintf
fclose(fin);
fclose(fout);
}