写了一个,看看能不能帮到你
#include<stdio.h>
#include<string.h>
#define NUM 50
void bubblesort(float *grade,char (*num)[20])
{
int i,j;
float temp;
char numtemp[NUM][20];
for(i=1;i<NUM;i++)
for(j=0;j<NUM-i;j++){
if(grade[j]<grade[j+1]){
temp=grade[j];
grade[j]=grade[j+1];
grade[j+1]=temp;
strcpy(numtemp[j],num[j]);
strcpy(num[j],num[j+1]);
strcpy(num[j+1],numtemp[j]);
}
}
}
int main(){
setbuf(stdout,NULL);
int i;
float grade[NUM];
char num[NUM][20];
for(i=0;i<NUM;i++){
printf("please input the %d info:\n",i+1);
scanf("%f",&grade[i]);
scanf("%s",num[i]);
}
bubblesort(grade,num);
printf("the result has been sortted:\n");
for(i=0;i<NUM;i++){
printf("the %d info:",i+1);
printf("grade:%5.2f num:%s\n",grade[i],num[i]);
}
return 0;
}
温馨提示:内容为网友见解,仅供参考