|
发表于 2023-12-12 16:27:41
|
显示全部楼层
下面是用C语言编写的实现上述功能的代码:
- #include <stdio.h>
- #define STUDENTS 10
- #define COURSES 5
- float scores[STUDENTS][COURSES];
- void inputScores() {
- printf("请输入%d个学生的%d门课的成绩:\n", STUDENTS, COURSES);
- for(int i = 0; i < STUDENTS; i++) {
- printf("请输入第%d个学生的成绩:\n", i+1);
- for(int j = 0; j < COURSES; j++) {
- scanf("%f", &scores[i][j]);
- }
- }
- }
- void calculateStudentAverage() {
- for(int i = 0; i < STUDENTS; i++) {
- float sum = 0;
- for(int j = 0; j < COURSES; j++) {
- sum += scores[i][j];
- }
- float average = sum / COURSES;
- printf("第%d个学生的平均分为:%f\n", i+1, average);
- }
- }
- void calculateCourseAverage() {
- for(int j = 0; j < COURSES; j++) {
- float sum = 0;
- for(int i = 0; i < STUDENTS; i++) {
- sum += scores[i][j];
- }
- float average = sum / STUDENTS;
- printf("第%d门课的平均分为:%f\n", j+1, average);
- }
- }
- void findHighestScore() {
- int highestStudent = 0;
- int highestCourse = 0;
- float highestScore = scores[0][0];
-
- for(int i = 0; i < STUDENTS; i++) {
- for(int j = 0; j < COURSES; j++) {
- if(scores[i][j] > highestScore) {
- highestScore = scores[i][j];
- highestStudent = i+1;
- highestCourse = j+1;
- }
- }
- }
-
- printf("最高分数为:%f,对应的学生是第%d个学生,课程是第%d门课\n", highestScore, highestStudent, highestCourse);
- }
- int main() {
- inputScores();
- calculateStudentAverage();
- calculateCourseAverage();
- findHighestScore();
-
- return 0;
- }
复制代码
你可以根据需要进行调整和扩展。希望对你有帮助!
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 |
|