#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[])
{
char cName[5][10]={"zhangsan","lisi","wangwu","zhaoliu","qianqi"};
int a,b,temp,pos;
float fScore[5]={55.0,79.0,88.0,98.0,66.0};
printf("排序前:\n");
for(a=0;a<5;a++)
{
printf("%s %.2f\n",cName[a],fScore[a]);
}
printf("\n\n");
printf("排序后:\n");
for(a=0;a<4;a++)
{
temp=fScore[a];
pos=a;
for(b=a+1;b<5;b++)
{
if(fScore[b]>temp)
{
temp=fScore[b];
pos=b;
}
}
fScore[pos]=fScore[a];
fScore[a]=temp;
}
for(a=0;a<5;a++)
{
printf("%s %.2f\n",cName[a],fScore[a]);
}
return 0;
}
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/209495080836121.png "#left")