第13周OJ练习-1 学生分数处理

来源:互联网 发布:ubuntu 访问网络命令 编辑:程序博客网 时间:2024/05/16 05:40

问题及代码

/*作者:贾如杉问题:在函数中输入n个人的成绩,计算最高分,最低分,总分和平均分输入学生人数n和n个学生的成绩。输出n个人的最高分,最低分,总分和平均分*/#include <stdio.h>double HighScore; /*全局变量,最高分*/double LowScore; /*全局变量,最低分*/double SumScore; /*全局变量,总分*/double AverageScore; /*全局变量,平均分*/void calcscore(int n); /*函数声明*/int main(){    int n;    scanf("%d",&n);    calcscore(n);    printf("%g %g %g %g\n",HighScore,LowScore,SumScore,AverageScore);    return 0;}void calcscore(int n){    int i;    double score,x,max,min,sum;    scanf("%lf",&score);    max=score;    min=score;    sum=score;    for(i=1; i<n; i++)    {        scanf("%lf",&score);        x=score;        if(max<x)        {            max=x;        }        if(min>x)        {            min=x;        }        sum=sum+x;    }    HighScore=max;    LowScore=min;    SumScore=sum;    AverageScore=sum/n;    return;}

运行结果:

知识点总结

      ;引用自定义函数,并使用循环和判断语句结局问题

学习心得

      加深对循环和判断的理解和使用,进一步了解自定义函数


0 0