c语言中如何实现从键盘中输入一个字符串设计函数sort函数实现该串中字符按从大到小输出?

如题所述

#include<stdio.h>

#include<string.h>

int sort(char a[])

{

for(int i=0;i<strlen(a);i++)

for(int j=0;j<strlen(a)-i-1;j++)

if(a[j]<a[j+1])

{

char t;

t=a[j];

a[j]=a[j+1];

a[j+1]=t;

}

for(int i=0;i<strlen(a);i++)

printf("%c ",a[i]);

}

int main()

{

char a[111];

gets(a);

sort(a);//调用函数 

return 0;

 } 

温馨提示:答案为网友推荐,仅供参考