鱼C论坛

 找回密码
 立即注册
查看: 2381|回复: 2

怎么都想不明白的!!!

[复制链接]
发表于 2014-10-17 00:58:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 水木人生88 于 2014-10-17 01:30 编辑

[i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i][i]求助啊!!!!不知道什么地方出错了!!!!!!!!![/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i]
有n各同学信息,按照成绩从高到底顺序输出各学生的信息!!!

#include"stdio.h"
struct student
{
int num;
char name[20];
float score;
};
void main()
{
struct student stu[5]={{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[j].score>stu[i].score)
   
    temp=stu[i];
                stu[i]=stu[j];   此处不知道怎么回事,写STU[I]总会变成stu
                stu[j]=temp;
  }
}
for(i=0;i<n;i++)
  printf("%6d%8s%6.2f\n",stu[i].num,stu[i].name,stu.score);
printf("\n");
}

[/i][/i][/i][/i][/i]
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2014-10-17 06:32:14 | 显示全部楼层
本帖最后由 machimilk 于 2014-10-17 06:35 编辑

没什么想不明白的,你错了好几个地方
改完了你对照一下

  1. #include"stdio.h"
  2. struct student
  3. {
  4.         int num;
  5.         char name[20];
  6.         float score;
  7. };
  8. int main()
  9. {
  10.         struct student stu[5]={{10101,"zhang",78},{10103,"wang",98.5},{10106,"li",86},{10108,"ling",73.5},{10110,"sun",100}};
  11.         struct student temp;
  12.         int n=5;
  13.         int i,j;
  14.         printf("the order is:\n");
  15.         for(i=0;i<n;i++)
  16.         {

  17.                 for(j=i+1;j<n;j++)
  18.                 {
  19.                         if(stu[j].score>stu[i].score)
  20.                         {
  21.                                 temp=stu[j];
  22.                                 stu[j]=stu[i];  // 此处不知道怎么回事,写STU[I]总会变成stu
  23.                                 stu[i]=temp;

  24.                         }

  25.                 }
  26.         }
  27.         for(i=0;i<n;i++)
  28.         printf("%6d%8s%8.2f\n",stu[i].num,stu[i].name,stu[i].score);
  29.         printf("\n");
  30.         return 0;
  31. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

头像被屏蔽
发表于 2014-10-30 19:02:45 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-18 20:12

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表