十三周—输出学生成绩

来源:互联网 发布:淘宝收藏率怎么算 编辑:程序博客网 时间:2024/06/05 07:30

问题与代码:

文件名称:输出学生成绩

作者:邓哲

时间:2016年11月25日09:07:59

#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;    HighScore=0,LowScore=101,SumScore=0;    for(i=1;i<=n;i++)    {        scanf("%lf",&score);        SumScore+=score;        if(score>HighScore)        {            HighScore=score;        }        if(score<LowScore)        {            LowScore=score;        }    }    AverageScore=SumScore/n;}


知识点总结:全局变量不能在函数中重新定义,否则为重复定义,直接在函数中赋值即可。


0 0
原创粉丝点击