|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
一个结构体数组,包含运动员信息,冒泡法按成绩排序,先输入,后排序,应该错在这地方!
#include<stdio.h>
struct sport
{
int num;
double grade;
};
main()
{
struct sport athlete[20];
int i,j,num;
double temp;
printf("input athlete info:\n");
printf("\t athlete number:\t");
scanf("%d",&num);
for(i=0;i<num;i++)
{
printf("\t input athlete num and grade:\t \n");
scanf("%d%lf",athlete[i].num,athlete[i].grade);
if(i==(num-1))
printf("input over!\n");
}
printf("\t Accroding to results of arrangement after the display sysrem!\n");
for(i=0;i<num;i++)
for(j=0;j<num-1;j++)
{
if(athlete[j].grade>athlete[j+1].grade)
{
temp=athlete[j].grade;
athlete[j].grade=athlete[j+1].grade;
athlete[j+1].grade=temp;
}
}
printf("\t \t end !\n" );
return 0;
}
|
|