填空题
下列给定程序中,函数fun()的功能是:读人一个字符串(长度<20),将该字符串中的所有字符按ASCⅡ码降序排序后输出。
#include<stdio.h>
void fun(char t[])
{
char c;
int i,j;
for(i=0;______;i++)/*第一空*/
for(j=i+1;j<=strlen(t);j++)
if(______)/*第二空*/
{
c=t[j];
t[j]=t[i];
t[i]=c;
}
}
main()
{
char s[81];
printf("Please enter a character string:\n");
gets(s);
printf("\n\nBefore sorting:\n%s",s);
______;/*第三空*/
printf("\nAfter sorting decreasingly:\n%s\n",s);
}
【参考答案】
i<=strlen(t)/*第一空。设定循环上限,以减少不必要的比较束提高程序效率*/