C语言:用函数调用的方法对30个学生求平均成绩、最高成绩、最低成绩。
2条回答 默认 最新
索利亚噶通 2021-12-09 21:42关注有用请采纳
#include<stdio.h> double averageScore(double score[], int n); // score存储分数, n为学员个数 double maxScore(double score[], int n); double minScore(double score[], int n); int main(){ double score[3]; // 30个分数 int n = 3; for (int i = 0; i < 3; i++) scanf("%lf", &score[i]); // 输入30个成绩 printf("平均分:%lf\n", averageScore(score, n)); printf("最大分数:%lf\n", maxScore(score, n)); printf("最小分数:%lf\n", minScore(score, n)); } double averageScore(double score[], int n){ double sumScore = 0.0; for(int i = 0; i < n; i++) sumScore += score[i]; return sumScore / n; } double maxScore(double score[], int n){ double maxscore = -1.0; for(int i = 0; i < n; i++) if (score[i] > maxscore) maxscore = score[i]; return maxscore; } double minScore(double score[], int n){ double minscore = 1000.0; for(int i = 0; i < n; i++) if (score[i] < minscore) minscore = score[i]; return minscore; }本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报