sse——输出最小国名

//编程实现从键盘输入5个国名(每个国名最长80个字符),
//找出并输出按字典顺序排在最前面的国名
//要求:
//(1)用gets输入字符串。
//(2)
//**输入提示信息为:"Input five countries' names:\n"
//**输出格式为:"The minimum is:%s\n"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 80
int main()
{
    char str[5][N];
    printf("Input five countries' names:\n");
    for (int i = 0; i < 5; i++)
    {
        gets(str[i]);
    }
    for (int j = 0; j < 4; j++)
    {
        for (int i = 0; i < 4; i++)
        {
            if (strcmp(str[i], str[i + 1]) > 0)
            {
                char temp[N];
                strcpy(temp, str[i]);
                strcpy(str[i], str[i + 1]);
                strcpy(str[i + 1], temp);
            }
        }

    }


    printf("The minimum is:%s\n", str[0]);


    return 0;
}

posted @ 2022-11-17 19:16  诩en  阅读(37)  评论(0)    收藏  举报