#include<stdio.h> #include<string.h> struct STD { int number; char name[10]; int score; }; int main() { struct STD stu[5]={{10001,"于港岩",95},{10002,"于港岩1",85},{10003,"于港岩2",97},{10004,"于港岩3",97},{10005,"于港岩4",91}},temp; struct STD *p; p=stu; int i,j; for(j=0;j<4;j++) { for(i=0;i<4;i++,p++) { if(stu[i].score <stu[i+1].score) { temp=stu[i] ; stu[i] =stu[i+1] ; stu[i+1]=temp; } } } for(i=0;i<5;i++) { printf("%d\t%s\t%d\n",stu[i].number ,stu[i].name ,stu[i].score ); } }
10003 于港岩2 97
10004 于港岩3 97
10001 于港岩 95
10005 于港岩4 91
10002 于港岩1 85
--------------------------------
Process exited after 0.01209 seconds with return value 0
请按任意键继续. . .
时间: 2024-11-05 06:03:58