C语言编写单科学生成绩
发布网友
发布时间:2022-06-04 04:57
我来回答
共1个回答
热心网友
时间:2023-10-26 19:04
#include "stdio.h"
#define N 16
int main(int argv,char *argc[]){
int s[N],i,d[5],sum;
printf("Please enter %d students' score(int, Separated by ' ')...\n",N);
for(sum=d[0]=d[1]=d[2]=d[3]=d[4]=i=0;i<N;i++){
while(scanf("%d",s+i)!=1 || s[i]<0 || s[i]>100){
printf("Input error, redo: ");
fflush(stdin);
}
s[i]>89 ? d[4]++ : s[i]<60 ? d[0]++ : d[s[i]/10-5]++;
sum+=s[i];
}
printf("\nThe AVERAGE are %g.\n",sum/(N+0.0));
printf("GRADE\tNUMBER\tPERCENTAGE\n");
printf("==========================\n");
for(i=4;i>=0;i--)
printf(" %c\t %d\t %6.2f%%\n",'E'-i,d[i],d[i]*100.0/N);
return 0;
}
运行结果如下: