赞
踩
1、输入6个字符串,并对它们按从小到大的顺序排序后输出。 char str[6][255] = {0}; //输入6个字符串 printf("请输入6个字符串:\n"); for (int i = 0; i < 6; i++) { scanf("%s", str[i]); } char temp[255] = {0}; //对字符串进行排序 for (int i = 0; i < 6 - 1; i++) { for (int j = 0; j < 6 - 1 - i; j++) { if (strcmp(str[j], str[j + 1]) > 0) { strcpy(temp, str[j]); strcpy(str[j], str[j + 1]); strcpy(str[j + 1], temp); } } } //对排好序的字符串数组进行输出 for (int i = 0; i < 6; i++) { printf("%s\n", str[i]); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。