学生成绩

问题:

  编写程序,键入10名学生的考试成绩(以百分制),统计总分及平均成绩并将结果输出。

分析:

  说明一个存放考试成绩的一维数组,每一数组元素代表某位学生的考试成绩。若假定学生的学号为1、2、3、4、.....、10,则为了使学号和下标一致,应指定数组的大小为11,另外,宜检验输入数据的合理性,因为考试成绩最少为0分,最多为100分,程序还应当安排输出格式。

 1 #include<stdio.h>
 2 #define NUMBER 10
 3 int main(){
 4     int score[NUMBER+1];
 5     int num,sum,total=0;
 6     for(num=1;num<=NUMBER;num++){
 7         do{
 8             printf("Enter score of student %2d: ",num);
 9             scanf("%d",&score[num]);
10         }while(!(score[num]>=0&&score[num]<=100));
11         total+=score[num];
12     }
13     printf("
");
14     printf("The total is:%5d
",total);
15     printf("The everage is:%5.1f
",(double)total/NUMBER);
16     return 0;
17 } 




原文地址:https://www.cnblogs.com/geziyu/p/8783404.html