在下面的程序中,用户将被要求输入一组字符串,程序将按字母升序对它们进行排序和显示。
#include<stdio.h>
#include<string.h>
int main(){
int i,j,count;
char str[25][25],temp[25];
puts("How many strings u are going to enter?: ");
scanf("%d",&count);
puts("Enter Strings one by one: ");
for(i=0;i<=count;i++)
gets(str[i]);
for(i=0;i<=count;i++)
for(j=i+1;j<=count;j++){
if(strcmp(str[i],str[j])>0){
strcpy(temp,str[i]);
strcpy(str[i],str[j]);
strcpy(str[j],temp);
}
}
printf("Order of Sorted Strings:");
for(i=0;i<=count;i++)
puts(str[i]);
return 0;
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Results: How many strings u are going to enter?: 5 Enter Strings one by one: I am a good guy You are a bad guy We are all good guy Both OK You can not go Order of Sorted Strings: Both OK I am a good guy We are all good guy You are a bad guy You can not go |
除教程外,本网站大部分文章来自互联网,如果有内容冒犯到你,请联系我们删除!