![](https://img2018.cnblogs.com/common/1315374/201912/1315374-20191220150034212-1987859600.png)
1 #include <stdio.h>
2 #include <string.h>
3
4 int main(void)
5 {
6 char str[5][80]; //二维数组保存5个字符串
7 int i, j;
8
9 for (i = 0; i < 5; i++)
10 {
11 scanf("%s", str[i]); //输入5个字符串
12 }
13
14 for (i = 0; i < 4; i++)
15 {
16 int index = i;
17 for (j = i + 1; j < 5; j++)
18 {
19 if (strcmp(str[index], str[j]) > 0)
20 {
21 index = j;
22 }
23 }
24 if (i != index)
25 {
26 char t[80];
27 strcpy(t, str[index]); //交换字符串
28 strcpy(str[index], str[i]);
29 strcpy(str[i], t);
30 }
31 }
32
33 printf("After sorted:\n");
34 for (i = 0; i < 5; i++)
35 {
36 puts(str[i]);
37 }
38
39 return 0;
40 }