#include <stdio.h>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
char m[5][80];
char n[80];
int i,j;
//输入5个字符串,存储在m中,
for(i=0;i<5;i++){
scanf("%s",&m[i]);
}
//比较字符串的大小
for(i=1;i<5;i++){
for(j=0;j<5-i;j++){
if(strcmp(m[j], m[j+1])>0){
strcpy(n, m[j]);
strcpy(m[j], m[j+1]);
strcpy( m[j+1],n);
}
}
}
printf("After sorted:\n");
for(i=0;i<5;i++){
printf("%s\n",m[i]);
}
return 0;
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交