/*
烟台大学计算机与控制工程学院
All rights reserved.
作者:汪莹莉
完成时间:2016年11月29日
题目描述
期末考试快到了,为了下学期开始的评优,院长给老师下达了任务--做一个统计学生成绩的程序,给他老人家省省事。任务内容是:
编写一个函数void calcscore(int n),在函数中输入n个人的成绩,计算最高分,最低分,总分和平均分,要求在主函数中调用函数calcscore计算各种成绩,并在主函数中输出各种计算结果。(使用全局变量在函数之间传递多个数据)
当然,老师不能把如此重大的任务全交给你做,他只是为了考考你,改了一个C语言版的小题目,由你来完成喽~
#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函数并提交
输入
学生人数n和n个学生的成绩。
输出
n个人的最高分,最低分,总分和平均分
样例输入
5
80 90 100 70 50
样例输出
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 x;
HighScore=-1;
LowScore=1000;
SumScore=0;
for (i=1; i<=n; i++)
{
scanf("%lf",&x);
if(x>HighScore)
HighScore=x;
if(x<LowScore)
LowScore=x;
SumScore+=x;
}
AverageScore=SumScore/n;
return;
}
运行结果:

知识点总结:函数在调用时注意函数赋值,如SumScore=0;自己在编译时忘记了
学习心得:C语言的学习是在不断地复习基础上再学习新的东西