c语言输出 成绩单

来源:百度知道 编辑:UC知道 时间:2024/06/19 19:13:11
输入4名学生的姓名及三门课成绩,打印学生成绩表。(姓名、三门课成绩、平均分)。试编写一个程序,包括主函数和如下子函数:
(1)输入每个学生的姓名及三门课成绩。
(2)计算每个学生的平均分。
(3)输出每个学生的姓名、三门课成绩及平均分。
并将输入的测试数据和运行结果写入实验报告。
提示:input函数完成每个学生的姓名及三门课成绩的录入。average函数计算每个学生的平均分,output函数输出每个学生的姓名、三门课成绩及平均分。

#include<stdlib.h>

typedef struct
{
char name[30];
double score[3];
}Table;

void Input( Table *t )
{
if (t!=NULL)
{
printf("Input the student's name:\n");
scanf("%s",t->name);
printf("Input the student's scores, from subject 1 to 3:\n");
scanf("%lf %lf %lf", &(t->score[0]), &(t->score[1]), &(t->score[2]) );
}
}

void Output( Table t[] )
{
double average( double s[]);
int i;
if (t!=NULL)
{

printf("\nName\tS1\tS2\tS3\tAve\n\n");

for(i=0; i<4; i++)
{
printf("%s\t%3.1f\t%3.1f\t%3.1f\t%4.2f\n", t[i].name, t[i].score[0],
t[i].score[1], t[i].score[2], average(t[i].score));
}
}
}

double average( double s[] )
{
int i