某医院想统计一下某项疾病的获得与否与年龄是否有关,需要对以前的诊断记录进行整理,按照0-18、19-35、36-60、61以上(含61)四个年龄段统计的患病人数占总患病人数的比例。
输入
共2行,第一行为过往病人的数目n(0 < n <= 100),第二行为每个病人患病时的年龄。
输出
按照0-18、19-35、36-60、61以上(含61)四个年龄段输出该段患病人数占总患病人数的比例,以百分比的形式输出,精确到小数点后两位。每个年龄段占一行,共四行。
样例输入
10
1 11 21 31 41 51 61 71 81 91
样例输出
20.00%
20.00%
20.00%
40.00%
#include<stdio.h>
main()
{
int n,x,i;
float a,b,c,d;
FILE *fin,*fout;
fin=fopen("nlyjb.in","r");
fout=fopen("nlyjb.out","w");
fscanf(fin,"%d",&n);
for(i=0;i<n;i++)
{fscanf(fin,"%d",&x);
if(x>=0 && x<=18) a++;
if(x>=19 && x<=35) b++;
if(x>=36 && x<=60) c++;
else d++;}
fprintf(fout,"%.2f%% \n%.2f%% \n%.2f%% \n%.2f%% \n",100/a,100/b,100/c,100/d);
fclose(fin);
fclose(fout);
}
请问这道题怎么错的
你这应该是fscanf的问题