编程作业:从键盘输入一个字符串,按照ASCII码值从小到大进行排序,输出排序后的字符串。

如题所述

#include<stdio.h>
void main() { char str[256],c; int i,j,n;
  gets(str); n=0; while ( str[n]!=0 ) n++;
  for ( i=0;i<n-1;i++ )
    for ( j=i+1;j<n;j++ )
      if ( str[i]>str[j] ) { c=str[i]; str[i]=str[j]; str[j]=c; }
  printf("%s\n",str);
}

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