C语言OJ项目参考(2969)学生成绩的处理

    xiaoxiao2026-03-30  15

    2969:学生成绩的处理

    Description   编写一个函数void calcscore(int n),在函数中输入n个人的成绩,计算最高分,最低分,总分和平均分,要求在主函数中调用函数calcscore计算各种成绩,并在主函数中输出各种计算结果。(使用全局变量在函数之间传递多个数据)

    #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; }

    主程序已给出,请完成calcscore函数并提交

    Input 学生人数n和n个学生的成绩。

    Output n个人的最高分,最低分,总分和平均分

    Sample Input 5 80 90 100 70 50

    Sample Output 100 50 390 78

    参考解答:

    #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 s; HighScore=-1; LowScore=1000; SumScore=0; for (i=0;i<n;i++) { scanf("%lf", &s); if(s>HighScore) HighScore=s; if(s<LowScore) LowScore=s; SumScore+=s; } AverageScore=SumScore/n; return; } 相关资源:董学良EXCEL记账修正版
    最新回复(0)