c语言设计学生结构体,c语言程序设计编程题目:请 :编写完成对学生相关信息的要求:1.定义一个结构体类型student,其中包括三个成...

该程序使用C语言定义了一个结构体`student`,包含学生学号、三门课程成绩、总分和平均成绩。通过输入10个学生的信息并进行排序,最后按总分降序输出所有学生的信息。程序中定义了`SortScore`函数用于成绩排序,`main`函数负责数据输入和输出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include

#include

#define STU_NUM 10 /*宏定义学生的数量*/

struct student /*定义一个结构体用来存放学生学号、三门课成绩、总分及平均成绩*/

{

char stu_id[20]; /*学生学号;*/

float score[3]; /*三门课成绩;*/

float total; /*总成绩;*/

float aver; /*平均成绩;*/

};

/*排序用一个函数来实现*/

void SortScore(student *stu,int n)

{

student stud;

for(int i = 0; i < n-1; i++)

for(int j = i+1 ; j < n; j++)

{

if(stu[i].total < stu[j].total)

{

stud = stu[i];

stu[i] = stu[j];

stu[j] = stud;

}

}

}

int main( )

{

student stu[STU_NUM]; /*创建结构体数组中有10个元素,分别用来保存这10个人的相关信息。*/

/*输入这十个学生的相关信息*/

for(int i = 0; i

{

printf("请输入第%d个学生的学号:",i+1);

scanf("%s",&stu[i].stu_id);

printf("输入第%d个学生的数学成绩:",i+1);

scanf("%f",&stu[i].score[0]);

printf("输入第%d个学生的英语成绩:",i+1);

scanf("%f",&stu[i].score[1]);

printf("输入第%d个学生的计算机成绩:",i+1);

scanf("%f",&stu[i].score[2]);

stu[i].total = stu[i].score[0]+stu[i].score[1]+stu[i].score[2];

stu[i].aver = stu[i].total/3;

}

printf("\n");

SortScore(stu,STU_NUM);/*调用排序函数*/

/*输出排序后的各学生的成绩*/

for(i = 0 ; i < STU_NUM; i++)

{

printf("序号: %d\t",i);

printf("学号:%s\t",stu[i].stu_id);

printf("数学:%f\t",stu[i].score[0]);

printf("英语:%f\t",stu[i].score[1]);

printf("计算机:%f\t",stu[i].score[2]);

printf("平均成绩:%f\t",stu[i].aver);

printf("总分:%f\t",stu[i].total);

printf("\n\n");

}

return 0;

}

注:(源程序中主要标识符含义说明)

#define STU_NUM 10 /*宏定义学生的数量*/

struct student /*定义一个结构体用来存放学生学号、三门课成绩、总分及平均成绩*/

{

char stu_id[20]; /*学生学号;*/

float score[3]; /*三门课成绩;*/

float total; /*总成绩;*/

float aver; /*平均成绩;*/

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值