你想让别人歪着脑袋照着你的图手工再敲一遍代码?
#include<stdio.h> int average_num(int a[],int n) { /**********Program**********/ int i,sum=0,x=0; double aver; for(i=0;i<n;i++) sum=sum+a[i]; aver=(double)sum/n; for(i=0;i<n;i++) if(a[i]<aver) x++; return x; /********** End **********/ } main() { int n,a[100],i,num; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); num=average_num(a,n); printf("the num is:%d\n",num); yzj(); } yzj() { FILE *IN,*OUT; int n; int i[10]; int o; IN=fopen("in.dat","r"); if(IN==NULL) { printf("Read File Error"); } OUT=fopen("out.dat","w"); if(OUT==NULL) { printf("Write File Error"); } for(n=0;n<5;n++) { fscanf(IN,"%d",&i[n]); } o=average_num(i,5); fprintf(OUT,"%d\n",o); fclose(IN); fclose(OUT); }
[此贴子已经被作者于2015-12-25 20:33编辑过]