C语言成绩管理系统:计算学生平均分、课程平均分及最高分

这篇文章将介绍如何使用C语言编写一个简单的成绩管理系统。该系统可以实现以下功能:

  1. 输入10个学生6门课的成绩。2. 计算并输出每个学生的平均分。3. 计算并输出每门课程的平均分。4. 找出所有60个分数中最高的分数,并输出对应的学生和课程。

代码实现c#include <stdio.h>

void inputScores(int scores[][6]) { printf('请输入10个学生的6门课成绩: '); for (int i = 0; i < 10; i++) { printf('请输入第%d个学生的6门课成绩: ', i+1); for (int j = 0; j < 6; j++) { scanf('%d', &scores[i][j]); } }}

void calculateStudentAverage(int scores[][6], float studentAverage[]) { for (int i = 0; i < 10; i++) { float sum = 0; for (int j = 0; j < 6; j++) { sum += scores[i][j]; } studentAverage[i] = sum / 6; }}

void calculateCourseAverage(int scores[][6], float courseAverage[]) { for (int j = 0; j < 6; j++) { float sum = 0; for (int i = 0; i < 10; i++) { sum += scores[i][j]; } courseAverage[j] = sum / 10; }}

void findHighestScore(int scores[][6], int *highestScore, int *studentIndex, int *courseIndex) { *highestScore = scores[0][0]; *studentIndex = 0; *courseIndex = 0; for (int i = 0; i < 10; i++) { for (int j = 0; j < 6; j++) { if (scores[i][j] > *highestScore) { *highestScore = scores[i][j]; *studentIndex = i; *courseIndex = j; } } }}

int main() { int scores[10][6]; float studentAverage[10]; float courseAverage[6]; int highestScore; int studentIndex; int courseIndex; inputScores(scores); calculateStudentAverage(scores, studentAverage); calculateCourseAverage(scores, courseAverage); findHighestScore(scores, &highestScore, &studentIndex, &courseIndex); printf('每个学生的平均分为: '); for (int i = 0; i < 10; i++) { printf('第%d个学生的平均分为:%.2f ', i+1, studentAverage[i]); } printf('每门课程的平均分为: '); for (int j = 0; j < 6; j++) { printf('第%d门课程的平均分为:%.2f ', j+1, courseAverage[j]); } printf('最高分为:%d,对应学生为第%d个,对应课程为第%d门 ', highestScore, studentIndex+1, courseIndex+1); return 0;}

代码解释

  • inputScores 函数用于输入10个学生6门课的成绩,并将成绩存储到二维数组 scores 中。* calculateStudentAverage 函数用于计算每个学生的平均分,并将结果存储到数组 studentAverage 中。* calculateCourseAverage 函数用于计算每门课程的平均分,并将结果存储到数组 courseAverage 中。* findHighestScore 函数用于查找所有成绩中的最高分,并返回最高分、对应学生和课程的索引。* main 函数是程序的入口,它调用上述函数来完成成绩管理系统的功能。

总结

这篇博客提供了一个用C语言编写的简单成绩管理系统,可以方便地计算学生平均分、课程平均分和最高分。你可以根据自己的需求对代码进行修改和扩展。

C语言成绩管理系统:计算学生平均分、课程平均分及最高分

原文地址: http://www.cveoy.top/t/topic/f4ln 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录