C语言笔记《九》
一维数组和函数综合编程练习
学生成绩统计 从键盘输入一个班(全班最多不超过30人) 学生某门课的成绩,当输入成绩为负值时,输入结束,分别实现下列功能: 统计不及格人数并打印不及格学生名单 统计成绩在全班平均分及平均分以上的学生人数,并打印这些学生的名单 统计各分数段的学生人数及所占的百分比.
# include<stdio.h>
# define N 30
main()
{int i,j,sum,average,low,high;
int a,b;
int result[N]={0};
char name[N][5];
sum=low=high=a=b=0;
for(i=0;i<N;i++)
{printf("name:");
scanf("%s",name[i]);
printf("result:");
scanf("%d",&result[i]);
if(result[i]<0) break;
}
printf("\nA list of failure is:\n");
for(j=0;j<i;j++)
{sum=sum+result[j];
if(result[j]<60)
{low++;
printf("%s ",name[j]);
}
}
printf("\nThe number of failure is: %d\n",low);
average=sum/i;
printf("The average of class results is: %d\n",average);
printf("A list of more than average is:\n");
for(j=0;j<i;j++)
{if(result[j]>average)
{high++;
printf("%s ",name[j]);
}
if(result[j]>80)
a++;
else if(result[j]>60)
b++;
}
printf("\nThe number of above average students is: %d\n",high);
printf("The percentage of outstanding students is: %f\n",((float)a/i));
printf("The percentage of good students is: %f\n",((float)b/i));
printf("The percentage of students who failed is: %f\n",((float)low/i));
getch();
}