输入三个字符串,按由小到大的顺序输出

/输入三个字符串,按由小到大的顺序输出/

#include <stdio.h>
#include <string.h>

int main(void)
{
    char str1[100], str2[100], str3[100];
    printf("请输入三个字符串:\n");
    scanf("%s %s %s", str1, str2, str3);
    if (strcmp(str1, str2) > 0)
    {
        char temp[100];
        strcpy(temp, str1);
        strcpy(str1, str2);
        strcpy(str2, temp);
    }
    if (strcmp(str1, str3) > 0)
    {
        char temp[100];
        strcpy(temp, str1);
        strcpy(str1, str3);
        strcpy(str3, temp);
    }
    if (strcmp(str2, str3) > 0)
    {
        char temp[100];
        strcpy(temp, str2);
        strcpy(str2, str3);
        strcpy(str3, temp);
    }
    printf("按由小到大的顺序输出的字符串为:%s %s %s\n", str1, str2, str3);
    return 0;
}

posted on 2024-07-09 23:01  wessf  阅读(65)  评论(0)    收藏  举报