标题:输入四个整数,要求按从小到大的顺序输出!
只看楼主
intachar
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2017-10-21
得分:0 
#include <stdio.h>
void main()
{
    int a=0,b=0,c=0,d=0,z=0;
    printf("请输入四个整数:\n");
    scanf("%d,%d,%d,%d",&a,&b,&c,&d);
    if((a)>(b)&&(a)>(c)&&(a)>(d)&&(b)>(c)&&(b)>(d)&&(c)>(d))
    z=1;
        else if(a>b&&a>c&&a>d&&b>c&&b>d&&d>c)
        z=2;
            else if(a>b&&a>c&&a>d&&c>b&&c>d&&b>d)
            z=3;
                else if(a>b&&a>c&&a>d&&c>b&&c>d&&d>b)
                z=4;
                    else if(a>b&&a>c&&a>d&&d>b&&d>c&&b>c)
                    z=5;
                        else if(a>b&&a>c&&a>d&&d>b&&d>c&&c>b)
                        z=6;
    else if(b>a&&b>c&&b>d&&a>c&&a>d&&c>d)
    z=7;
        else if(b>a&&b>c&&b>d&&a>c&&a>d&&d>c)
        z=8;
            else if(b>a&&b>c&&b>d&&c>a&&c>d&&a>d)
            z=9;
                else if(b>a&&b>c&&b>d&&c>a&&c>d&&d>a)
                z=10;
                    else if(b>a&&b>c&&b>d&&d>a&&d>c&&a>c)
                    z=11;
                        else if(b>a&&b>c&&b>d&&d>a&&d>c&&c>a)
                        z=12;
    else if(c>a&&c>b&&c>d&&a>b&&a>d&&b>d)
    z=13;
        else if(c>a&&c>b&&c>d&&a>b&&a>d&&d>b)
        z=14;
            else if(c>a&&c>b&&c>d&&b>a&&b>d&&a>d)
            z=15;
                else if(c>a&&c>b&&c>d&&b>a&&b>d&&d>a)
                z=16;
                    else if(c>a&&c>b&&c>d&&d>a&&d>b&&a>b)
                    z=17;
                        else if(c>a&&c>b&&c>d&&d>a&&d>b&&b>a)
                        z=18;
    else if(d>a&&d>b&&d>c&&a>b&&a>c&&b>c)
    z=19;
        else if(d>a&&d>b&&d>c&&a>b&&a>c&&c>b)
        z=20;
            else if(d>a&&d>b&&d>c&&b>a&&b>c&&a>c)
            z=21;
                else if(d>a&&d>b&&d>c&&b>a&&b>c&&c>a)
                z=22;
                    else if(d>a&&d>b&&d>c&&c>a&&c>b&&a>b)
                    z=23;
                        else if(d>a&&d>b&&d>c&&c>a&&c>b&&b>a)
                        z=24;

        switch(z)
        {
            case 1 : printf("%d,%d,%d,%d\n",d,c,b,a);break;
                case 2 : printf("%d,%d,%d,%d\n",c,d,b,a);break;
                    case 3 : printf("%d,%d,%d,%d\n",d,b,c,a);break;
                        case 4 : printf("%d,%d,%d,%d\n",b,d,c,a);break;
                            case 5 : printf("%d,%d,%d,%d\n",c,b,d,a);break;
                                case 6 : printf("%d,%d,%d,%d\n",b,c,d,a);break;
            case 7 : printf("%d,%d,%d,%d\n",d,c,a,d);break;
                case 8 : printf("%d,%d,%d,%d\n",c,d,a,b);break;
                    case 9 : printf("%d,%d,%d,%d\n",d,a,c,b);break;
                        case 10 : printf("%d,%d,%d,%d\n",a,d,c,b);break;
                            case 11 : printf("%d,%d,%d,%d\n",c,a,d,b);break;
                                case 12 : printf("%d,%d,%d,%d\n",a,c,d,b);break;
            case 13 : printf("%d,%d,%d,%d\n",d,b,a,c);break;
                case 14 : printf("%d,%d,%d,%d\n",b,d,a,c);break;
                    case 15 : printf("%d,%d,%d,%d\n",d,a,b,c);break;
                        case 16 : printf("%d,%d,%d,%d\n",a,d,b,c);break;
                            case 17 : printf("%d,%d,%d,%d\n",b,a,d,c);break;
                                case 18 : printf("%d,%d,%d,%d\n",a,b,d,c);break;
            case 19 : printf("%d,%d,%d,%d\n",c,b,a,d);break;
                case 20 : printf("%d,%d,%d,%d\n",b,c,a,d);break;
                    case 21 : printf("%d,%d,%d,%d\n",c,a,b,d);break;
                        case 22 : printf("%d,%d,%d,%d\n",a,c,b,d);break;
                            case 23 : printf("%d,%d,%d,%d\n",b,a,c,d);break;
                                case 24 : printf("%d,%d,%d,%d\n",a,b,c,d);break;
        
        }
}

刚学的,我编的太复杂了;楼主赋值语句“d=a;”改成“d=t;”就好了
2017-10-21 18:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-135315-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.275169 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved