发布网友 发布时间:2022-06-16 16:14
共1个回答
热心网友 时间:2023-11-04 16:49
#include<stdio.h>#include<stdlib.h>struct Student{ int num; char name[20]; float score;};int main(){ struct Student stu[5]={{10101,"Zhang",78},{10103,"Wang",98.5},{10106,"Li",86},{10108,"Ling",73.5},{10110,"Sun",100}}; int n=5; int i; int j; struct Student temp; printf("The order is:\n"); for(i=n-1;i>0;i--){ for(j=0;j<i;j++){ if(stu[j].score<stu[j+1].score){ temp=stu[j]; stu[j]=stu[j+1]; stu[j+1]=temp; } } } for(i=0;i<n;i++)//你这里多了个分号!!!!!!!!!!!!!!! printf("%-6d%-8s%-6.2f\n",stu[i].num,stu[i].name,stu[i].score); printf("\n"); //system("pause"); return 0;}
排序算法改成冒泡了。结果如下: