#include<stdio.h>
struct student
{
char name[10];
int score[3];
int sum;
}stu[50];
void sort(struct student st[],int n);
int main()
{
int i,j,n,s;
printf("input number of students:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("input data of student %d:\n,"),i+1;
printf("input name:");
scanf("%s",stu[i].name);
printf("input score1 score2 score3:");
s=0;
for(j=0;j<n;j++)
{
scanf("%d",&stu[i].score[j]);
s+=stu[i].score[j];
}
stu[i].sum=s;
}
sort(stu,n);
for(i=0;i<n-1;i++)
printf("%-10s,%d,%d,%d,%d\n",stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].sum);
}
void sort(struct student st[],int n)
{
int i,j,k;
struct student t;
for(i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
if(st[k].sum<st[j].sum)
k=j;
if(k!=j)
{
t=st[i];
st[i]=st[k];
st[k]=t;
}
}
}
C语言:用结构体记录一个班级同学的学号,姓名,三科成绩和总成绩。用程序实现输入全班每个学生的信息和三科成绩,并按总成绩排名输出
最新推荐文章于 2024-03-26 12:22:28 发布