C 语言程序设计实验报告
实验七、结构体程序设计
【实验目的】
(1)掌握结构体类型的概念、定义和使用;
(2)掌握结构体数组、结构体指针的定义和使用;
【实验内容及步骤】
1、输入 5 位同学的一组信息,包括学号、姓名、数学成绩、计算机成绩,
求得每位同学的平均分和总分,然后按照总分从高到低排序。
【程序代码】:
struct student
{
int num;
char name[10];
double math_score;
double computer_score;
};
#include<stdio.h>
main()
{
struct student std[5],std_temp;
int i,j,temp;
double sum[5],aver[5];
for(i=0;i<5;i++)
{
printf("输入第%d 学生的学号、姓名、数学成绩、计算机成绩: \
n",i+1);
scanf("%d%s%lf
%lf",&std[i].num,&std[i].name,&std[i].math_score,&std[i].computer_s
core);
}
printf("您输入的学生信息为:");
for(i=0;i<5;i++)
{