求平均成绩

Problem Description
假设一个班有n(n<=50)个学生,每人考m(m<=5)门课,求每个学生的平均成绩和每门课的平均成绩,并输出各科成绩均大于等于平均成绩的学生数量。
 
Input
输入数据有多个测试实例,每个测试实例的第一行包括两个整数n和m,分别表示学生数和课程数。然后是n行数据,每行包括m个整数(即:考试分数)。
 
Output
对于每个测试实例,输出3行数据,第一行包含n个数据,表示n个学生的平均成绩,结果保留两位小数;第二行包含m个数据,表示m门课的平均成绩,结果保留两位小数;第三行是一个整数,表示该班级中各科成绩均大于等于平均成绩的学生数量。
每个测试实例后面跟一个空行。
 
Sample Input
2 2
5 10
10 20
 
Sample Output
7.50 15.00
7.50 15.00
1
 
 1 #include <stdio.h>
 2 
 3 int main(){
 4     int n;
 5     int m;
 6     int i;
 7     int j;
 8     int score[51][6];
 9     double student_score;
10     double course_score;
11     double average_score[6];
12     int flag;
13     int amount;
14     
15     while((scanf("%d%d",&n,&m))!=EOF){
16         amount=0;
17         for(i=0;i<n;i++){
18             for(j=0;j<m;j++){
19                 scanf("%d",&score[i][j]);
20             }
21         }
22         
23         for(i=0;i<n;i++){
24             student_score=0;
25             for(j=0;j<m;j++){
26                 student_score+=score[i][j];
27             }
28             
29             if(i==0)
30                 printf("%.2lf",student_score/m);
31                 
32             else
33                 printf(" %.2lf",student_score/m);
34         }
35         
36         printf("
");
37         
38         for(j=0;j<m;j++){
39             course_score=0;
40             for(i=0;i<n;i++){
41                 course_score+=score[i][j];
42             }
43             average_score[j]=course_score/n;
44             
45             if(j==0)
46                 printf("%.2lf",course_score/n);
47                 
48             else
49                 printf(" %.2lf",course_score/n);
50         }
51         
52         printf("
");
53         
54         for(i=0;i<n;i++){
55             flag=0;
56             for(j=0;j<m;j++){
57                 if(score[i][j]<average_score[j]){
58                     flag=1;
59                     break;
60                 }
61             }
62             if(flag==0)
63                 amount++;
64         }
65         
66         printf("%d

",amount);
67     }    
68     
69     return 0;
70 }
原文地址:https://www.cnblogs.com/zqxLonely/p/4056524.html