雪糕会长 2021-12-09 21:30 采纳率: 66.7%
浏览 101
已结题

C语言:用函数调用的方法对30个学生求平均成绩、最高成绩、最低成绩。

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;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 12月17日
  • 已采纳回答 12月9日
  • 创建了问题 12月9日

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改