1414 成绩系统之平均成绩
Time Limit : 2000/1000 MS(Java/Others) | Memory Limit : 65536/32768 KB(Java/Others)
Submits : 3 | Solved : 0
Description
陈老师布置同学们完成一个小型的成绩管理系统,现在希望你设计其中的一个求平均值的模块。已知有n个学生,每个学生信息包含学号、姓名、性别、3门课程成绩,现在请你设计函数,完成对每个学生3门课程求平均,并输出相应信息。
Input
先输入一个整数n表示有n个学生信息。(假设学生最多有50人)
接着输入这n个学生的学号、姓名(不超过20个字符,可能带空格)、性别、3门课程成绩。
Output
输出每个学生的学号、姓名、3门课程成绩以及平均成绩(保留1位小数)。
Sample Input
2 15001 Peter Li m 90 91 92 15002 Susan Wang f 81 82 83
Sample Output
---Student Information--- 15001 Peter Li 90 91 92 91.0 15002 Susan Wang 81 82 83 82.0
Template
#include<stdio.h>
typedef struct student
{ int ID;
char Name[20];
char Gender;
int score[3];
double ave;
}STU;
void add(STU *p,int size); //函数,实现学生的信息输入
void average(STU *p,int size); //函数,求学生平均成绩
void disp(STU *p,int size); //函数,实现学生的信息输出
int main()
{
STU s[50];
int n;
scanf("%d",&n);
add(s,n);
average(s,n);
disp(s,n);
return 0;
}
@-@ //设计函数完成信息输入
@-@ //设计函数求每个学生的平均分
void disp(STU *p,int size)
{
int i,j;
printf("---Student Information---\n");
for(i=0;i<size;i++)
{
printf("%d ",p->ID);
printf("%-20s ",p->Name);
for(j=0;j<3;j++)
printf("%d ",p->score[j]);
printf("%.1lf ",p->ave);
printf("\n");
p++;
}
}
HINT
add函数中的部分输入参考
scanf("%d ",&p->ID); //后注,如果PE,把%d后空格去掉;另,复查下测试数据
gets(p->Name);
Source
NBU OJ
浙公网安备 33020402000166号