复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54#include<stdio.h> #include<string.h> /* 从键盘上输入5个字符,char str[5][20] 按照字符串的长度将字符串按从小到大的顺序排序 按照字符串的大小将字符串按从小到大的顺序排序 */ int main(void){ char str[5][20]={0}; int i =0; int j=0; char temp[20]={0}; //先输入5个字符串 printf("请输入5个字符串:"); for(i=0;i<5;i++){ scanf("%s",str[i]); } //然后求每一行的长度 就是吧[5][20]的分为5个[20]的 //长度已经被我封装在le[]数组中 //然后排序 for(j = 0;j < ROW - 1;j++) { for(i = 0;i < ROW- j -1;i++) { if(strlen(str[i]) > strlen(str[i+1])) { strcpy(temp,str[i]); //temp 是首地址 strcpy(str[i],str[i+1]); strcpy(str[i+1],temp); } } } } for(i=0;i<5;i++){ printf("%s ",str[i]); } return 0; }
最后
以上就是幸福荔枝最近收集整理的关于【C语言】从键盘上输入5个字符串,char str[5][20] 按照字符串的长度将字符串按从小到大的顺序排序的全部内容,更多相关【C语言】从键盘上输入5个字符串,char内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复