/***************************************************************
C语言
AUTHOR:liuyongshui
问题来源:http://blog.csdn.net/sxhelijian/article/details/8620846
***************************************************************/
/*
问题十六:每位同学的信息学号、姓名、C++、高数、英语成绩,定义一个学生成绩的结构体数组,其中的数据成员包括学号(char num[12])、姓名(name)、三门课的成绩(grade)、总分(score)、均分(average))。
(1)从键盘上输入5名学生的信息;
(2)求出每名同学的总分和均分,并存储在结构体数组中(可以读入过程中“顺便”计算);
(3)输出求出每位同学的信息学号、姓名、总分和均分。
*/
#include <stdio.h>
struct stu
{
char num[12];
char name[15];
float cpp;
float english;
float math;
float score;
float average;
};
void calculate (struct stu scholastic[] ); //计算学生成绩总分和平均分
int main()
{
int i;
struct stu student[5];
printf("请输入五个同学信息.......\n");
printf("学号\t姓名\t英语分数\t高数\tC++分数\n");
for(i=0; i<5; i++)
{
scanf("%s %s %f %f %f", student[i].num,
student[i].name, &student[i].english,
&student[i].math, &student[i].cpp);
}
calculate(student);
return 0;
}
// 函数的定义
void calculate (struct stu scholatic[] )
{
int i;
for(i=0; i<5; i++)
{
scholatic[i].score=scholatic[i].average=0.0;
scholatic[i].score= scholatic[i].math+
scholatic[i].english+
scholatic[i].cpp;
scholatic[i].average=scholatic[i].score/3;
}
printf("输出每个同学的总分和平均分:\n");
for(i=0; i<5; i++)
{
printf("第%d人: 学号:%s 姓名:%s 总分:%f 平均分:%f\n", i+1, scholatic[i].num,
scholatic[i].name,
scholatic[i].score,
scholatic[i].average);
}
}
C语言
AUTHOR:liuyongshui
问题来源:http://blog.csdn.net/sxhelijian/article/details/8620846
***************************************************************/
/*
问题十六:每位同学的信息学号、姓名、C++、高数、英语成绩,定义一个学生成绩的结构体数组,其中的数据成员包括学号(char num[12])、姓名(name)、三门课的成绩(grade)、总分(score)、均分(average))。
(1)从键盘上输入5名学生的信息;
(2)求出每名同学的总分和均分,并存储在结构体数组中(可以读入过程中“顺便”计算);
(3)输出求出每位同学的信息学号、姓名、总分和均分。
*/
#include <stdio.h>
struct stu
{
char num[12];
char name[15];
float cpp;
float english;
float math;
float score;
float average;
};
void calculate (struct stu scholastic[] ); //计算学生成绩总分和平均分
int main()
{
int i;
struct stu student[5];
printf("请输入五个同学信息.......\n");
printf("学号\t姓名\t英语分数\t高数\tC++分数\n");
for(i=0; i<5; i++)
{
scanf("%s %s %f %f %f", student[i].num,
student[i].name, &student[i].english,
&student[i].math, &student[i].cpp);
}
calculate(student);
return 0;
}
// 函数的定义
void calculate (struct stu scholatic[] )
{
int i;
for(i=0; i<5; i++)
{
scholatic[i].score=scholatic[i].average=0.0;
scholatic[i].score= scholatic[i].math+
scholatic[i].english+
scholatic[i].cpp;
scholatic[i].average=scholatic[i].score/3;
}
printf("输出每个同学的总分和平均分:\n");
for(i=0; i<5; i++)
{
printf("第%d人: 学号:%s 姓名:%s 总分:%f 平均分:%f\n", i+1, scholatic[i].num,
scholatic[i].name,
scholatic[i].score,
scholatic[i].average);
}
}