用 fopen fscanf fprintf 读写文件
#include<stdio.h> #define INF 100000000 int main() { FILE *fin,*fout; fin=fopen("data.in","rb"); fout=fopen("data.out","wb"); int x,n=0,mn=INF,mx=-INF,s=0; while(fscanf(fin,"%d",&x)==1) { s+=x; if(x>mx) mx=x; if(x<mn) mn=x; n++; } fprintf(fout,"max=%d min=%d average=%.3lf\n",mx,mn,s*1.0/n); fclose(fin); fclose(fout); return 0; }