请编惃程序,定义惆于存储学惄高考惁息的结构体数组,输入学惄的准考证号、姓名和成绩惁息,惀算每位学惄的总分,并按总分由高到低输惂学惄惁息悿。 输入样例: 1001 aaa 90 90 90 210 1002 zzz 100 110 110 220 q 输惂样例: 1002 zzz 100.00 110.00 110.00 220.00 540.00 1001 aaa 90.00 90.00 90.00 210.00 480.00
时间: 2023-03-14 09:03:30 浏览: 33
答案:#include<stdio.h>
#define MAXSIZE 10
struct student
{
int num; //准考证号
char name[20]; //姓名
float score[3]; //三门成绩
float total; //总分
} stu[MAXSIZE]; int main()
{
int i, j, n;
struct student temp;
printf("请输入学生人数:");
scanf("%d", &n);
printf("请输入学生准考证号,姓名,三门成绩:\n");
for(i=0; i<n; i++)
{
scanf("%d%s%f%f%f", &stu[i].num, stu[i].name, &stu[i].score[0], &stu[i].score[1], &stu[i].score[2]);
stu[i].total=stu[i].score[0]+stu[i].score[1]+stu[i].score[2];
}
for(i=0; i<n-1; i++)
for(j=0; j<n-i-1; j++)
if(stu[j].total<stu[j+1].total)
{
temp=stu[j];
stu[j]=stu[j+1];
stu[j+1]=temp;
}
printf("按总分从高到低输出学生成绩:\n");
printf("准考证号\t姓名\t三门成绩\t总分\n");
for(i=0; i<n; i++)
printf("%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n", stu[i].num, stu[i].name, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].total);
return 0;
}
相关推荐
![asp](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)