如何用C语言编写用结构体完成N个学生M名课程的成绩排序?
1个回答
展开全部
这里是4名学生一门成绩的排序,不过中间还有生日,希望能给你带来点灵感吧!源代码如下:
#include <stdio.h>
struct student_record
{
char name[8];
struct birth
{
int year;
int month;
int day;
}date;
int score;
}student[4];
void main()
{
struct student_record student[4];
struct student_record stu;
int i,j;
printf("please input date:\n");
for(i=0;i<4;i++)
scanf("%s%d%d%d%d",student[i].name,&student[i].date.year,
&student[i].date.month,&student[i].date.day,&student[i].score);
printf("OUTPUT:\n");
printf("NAME BIRTH SCORE\n");
for(j=1;j<=3;j++)
for(i=0;i<4-j;i++)
{
if(student[i].score<student[i+1].score)
{
stu=student[i];
student[i]=student[i+1];
student[i+1]=stu;
}
}
for(i=0;i<4;i++)
printf("%s %d,%d,%d %d\n",student[i].name,student[i].date.year,
student[i].date.month,student[i].date.day,student[i].score);
}
#include <stdio.h>
struct student_record
{
char name[8];
struct birth
{
int year;
int month;
int day;
}date;
int score;
}student[4];
void main()
{
struct student_record student[4];
struct student_record stu;
int i,j;
printf("please input date:\n");
for(i=0;i<4;i++)
scanf("%s%d%d%d%d",student[i].name,&student[i].date.year,
&student[i].date.month,&student[i].date.day,&student[i].score);
printf("OUTPUT:\n");
printf("NAME BIRTH SCORE\n");
for(j=1;j<=3;j++)
for(i=0;i<4-j;i++)
{
if(student[i].score<student[i+1].score)
{
stu=student[i];
student[i]=student[i+1];
student[i+1]=stu;
}
}
for(i=0;i<4;i++)
printf("%s %d,%d,%d %d\n",student[i].name,student[i].date.year,
student[i].date.month,student[i].date.day,student[i].score);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询