有没有大佬 求c语言程序

有没有大佬 求c语言程序用记事本建立一个数据文件data1.txt,内容为30位学生的成绩(即30个0~100之间的整数),各成绩用空格分隔。编程读取该文件各数据,统计90~100、80~89、70~79、60~69、60以下的人数以及各自所占百分比,结果写到文件data2.txt中。
提示:文件的读和写使用文件的格式输入输出函数fscanf() 和 fprintf() 。

#include<stdio.h>
#include<stdlib.h>

int main()
{
char msg[]={-56,-25,-71,-5,-78,-55,-60,-55,-93,-84,-57,-21,-72,-8,-50,-46,50,48,48,-78,-
58,-72,-69,-93,-95,0};
printf("%s\n\n",msg);

const int N=30;
int rsh[5]={0};
char f1[]="data1.txt",f2[]="data2.txt";
int scores[N],i;
FILE *inf,*outf;
inf=fopen(f1,"r");
outf=fopen(f2,"w");
for(i=0;i<N;i++)
{
fscanf(inf,"%d",&scores[i]);
if(scores[i]>=90)
{
rsh[0]++;
}
else if(scores[i]>=80)
{
rsh[1]++;
}
else if(scores[i]>=70)
{
rsh[2]++;
}
else if(scores[i]>=60)
{
rsh[3]++;
}
else
{
rsh[4]++;
}
}
for(i=0;i<5;i++)
{
fprintf(outf,"%d\t%%%f\n",rsh[i],((float)rsh[i]/N)*100);
}
fclose(inf);
fclose(outf);
system("PAUSE");
return EXIT_SUCCESS;
}
//data1.txt
//88 70 55 64 90 87 72 40 61 58 93 45 77 66 29 61 58 78 77 80 99 82 76 49 81 73 92 87 51 60
温馨提示:答案为网友推荐,仅供参考
相似回答