• 对输入的单词进行排序


    代码如下:

    #include<stdio.h>
    #include<string.h>
    
    int main()
    {
        int i,j;
        char word[5][20];
        printf("请输入要排序的五个单词:");
        for(i=0;i<5;i++)
        {
            scanf("%s",&word[i]);
        }
        // 使用冒泡法对单词进行排序
        for(i=0;i<5;i++)
        {
            for(j=0;j<4;j++)
            {
                if(strcmp(word[j],word[j+1])<0)
                {
                    char *p;
                    char m[20];
                    p = m;
                    strcpy(p,word[j]);
                    strcpy(word[j],word[j+1]);
                    strcpy(word[j+1],p);
                }
            }
        }
        // 输入排序后的单词
        printf("排序后:
    ");
        for(i=0;i<5;i++)
        {
            printf("%s ",word[i]);
        }
        return 0;
    }

    运行效果

  • 相关阅读:
    asp.net读取/导入project(mpp)文件
    hdu2103
    hdu2100(大数加)
    hdu1406
    hdu1249
    hdu1038
    hdu2565
    hdu1203
    zoj3501
    hdu2102
  • 原文地址:https://www.cnblogs.com/ncuhwxiong/p/7803459.html
Copyright © 2020-2023  润新知