怎么都想不明白的!!!
本帖最后由 水木人生88 于 2014-10-17 01:30 编辑求助啊!!!!不知道什么地方出错了!!!!!!!!!
有n各同学信息,按照成绩从高到底顺序输出各学生的信息!!!
#include"stdio.h"
struct student
{
int num;
char name;
float score;
};
void main()
{
struct student stu={{10101,"zhang",78},{10103,"wang",98.5},{10106,"li",86},{10108,"ling",73.5},{10110,"sun",100}};
struct student temp;
const int n=5;
int i,j;
printf("the order is:\n");
for(i=0;i<n-1;i++)
{
for(j=i+1;j<5;j++)
{
if(stu.score>stu.score)
temp=stu;
stu=stu; 此处不知道怎么回事,写STU总会变成stu
stu=temp;
}
}
for(i=0;i<n;i++)
printf("%6d%8s%6.2f\n",stu.num,stu.name,stu.score);
printf("\n");
}
本帖最后由 machimilk 于 2014-10-17 06:35 编辑
没什么想不明白的,你错了好几个地方
改完了你对照一下
#include"stdio.h"
struct student
{
int num;
char name;
float score;
};
int main()
{
struct student stu={{10101,"zhang",78},{10103,"wang",98.5},{10106,"li",86},{10108,"ling",73.5},{10110,"sun",100}};
struct student temp;
int n=5;
int i,j;
printf("the order is:\n");
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(stu.score>stu.score)
{
temp=stu;
stu=stu;// 此处不知道怎么回事,写STU总会变成stu
stu=temp;
}
}
}
for(i=0;i<n;i++)
printf("%6d%8s%8.2f\n",stu.num,stu.name,stu.score);
printf("\n");
return 0;
}
页:
[1]