酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

c语音 声明3个长度为30的字符串s1,s2,s3,将他们作为input函数的参数,并使用input输入这三个字符串。再将这三个变量作为sort函数的参数,再使用sort参数将这三个字符串按降序排列,并在主函数中将他们输出。 输入格式: "%s%s%s" 输出格式: "%s %s %s\n" 输入样例: 111 222 333↙ 输出样例: 333 222 111↙

以下是使用 C 语言解决此问题的代码: ```c #include <stdio.h> #include <string.h> // 交换函数 void swap(char *str1, char *str2) { char temp[30]; strcpy(temp, str1); strcpy(str1, str2); strcpy(str2, temp); } // 排序函数 void sort(char *s1, char *s2, char *s3) { if (strcmp(s1, s2) < 0) { swap(s1, s2); } if (strcmp(s1, s3) < 0) { swap(s1, s3); } if (strcmp(s2, s3) < 0) { swap(s2, s3); } } int main() { char s1[30], s2[30], s3[30]; printf("请输入三个字符串: "); scanf("%s%s%s", s1, s2, s3); sort(s1, s2, s3); printf("%s %s %s\n", s1, s2, s3); return 0; } ``` [2024-10-25 00:53:58 | AI写代码神器 | 290点数解答]

相关提问