代码如下:
#include
#include
int main()
{
char str[] = "Hello World!", ch;
int i, j, len;
len = strlen(str);
for (i = 0; i < len - 1; i++) {
for (j = i + 1; j < len; j++) {
if (str[i] > str[j]) {
ch = str[i];
str[i] = str[j];
str[j] = ch;
}
}
}
printf("%s\n", str);
return 0;
}
运行结果:
#include "stdio.h"
#include "string.h"
int main()
{char s[100],t;
int i,j,sum;
printf("Input:\n");
gets(s);
sum=strlen(s);
for(i=0;i
printf("Output:\n");
puts(s);
return 0;
}
#include
#include
void sort(char *str,int len)
{
int i,j;
char ch;
for(i=0;i
for(j=0;j
ch = str[i];
str[i] = str[j];
str[j] = ch;
}
}
}
int main(void)
{
char str[120];
int len;
printf("请输入字符串:");
scanf("%s",str);
len = strlen(str);
sort(str,len);
printf("%s \n",str);
return 0;
}
谢谢!满意请采纳!