题目:编写一个程序输入一个平均成绩和姓名,将成绩按递减顺序排序,输出排序后的成绩和姓名。

2024-10-30 08:46:17
推荐回答(1个)
回答1:

/* 人数 */
#define N 4
/* 姓名长度 */
#define M 50
#include
#include

void jiaohuan(char *x, char *y)
{
int L,i;
char c;
L = strlen(x);
if (strlen(y) > L) L = strlen(y); /* 按长度交换 */
for (i=0;i}

main()
{
char str[N][M] ;
int i,j,a,s[N];
for(i=0;iprintf("name :");
scanf("%s",str[i]);
printf("source :");
scanf(" %d",&s[i]);
printf("\n");
}
for(i=0;iprintf("name is :%s\tsource is :%d\n",str[i],s[i]);}
for(i=0;ifor(j=i+1;jif(s[i]>s[j]){ /* 按成绩由低到高排序*/
a=s[i];
s[i]=s[j];
s[j]=a;
jiaohuan(str[i],str[j]);
}
printf("\n");
for(i=0;iprintf("name is :%s\tsource is :%d\n",str[i],s[i]);}
getch();

}