题解 | #班级成绩输入输出#
班级成绩输入输出
https://www.nowcoder.com/practice/60d96b08e1cb42e38629d54e37eac008
#define STUDENTS 5 #define LESSONS 5 int main() { float grades[STUDENTS][LESSONS]; int stu = 0, lesson = 0; float sum = 0; for (stu = 0; stu < STUDENTS; stu++) { for (lesson = 0; lesson < LESSONS; lesson++) { scanf("%f", &grades[stu][lesson]); } } for (stu = 0; stu < STUDENTS; stu++) { sum = 0; for (lesson = 0; lesson < LESSONS; lesson++) { printf("%.1f ", grades[stu][lesson]); sum += grades[stu][lesson]; } printf("%.1f\n", sum); } return 0; }
数组版本