|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
为什么输出会是三个0呢???无法理解
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct student
{char name[20];
int age;
float score;
}ST;
int main ()
{ST stu[]={{"张三",18,81},{"王四",19,90},{"小二",21,93}};
strcpy(stu[0].name,"张三");
strcpy(stu[1].name,"王四");
strcpy(stu[2].name,"小二");
int i;
int j;
int n=3;
for (i=1;i<=3;i++)
{for (j=1;j<n-1-1;j++)
{if (stu[j].score>stu[j+1].score);
ST S;
S=stu[j];
stu[j]=stu[j+1];
stu[j+1]=S;
}
}
//输出
for (i=1;i<=3;i++)
printf("%d\n",stu[i].score);
getchar();
return 0;}
本帖最后由 jackz007 于 2020-12-30 01:55 编辑
用 "%d" 去显示一个浮点数还能不是 0 ?
typedef struct student {
char name[20];
int age;
float score ;
} ST ;
. . . . . .
printf("%d\n" , stu[ i ] . score) ;
|
|