Biggest and smallest of four integers (No arrays, no functions, fewest 'if' statements)

后端 未结 18 2543
北海茫月
北海茫月 2020-12-10 11:29

You see, I\'ve self-taught myself C++ (not completely, I\'m still procrastinating -_-). So, now I started university and they\'re teaching C and they made us do a program of

18条回答
  •  清歌不尽
    2020-12-10 11:48

    I saw this answer that used for loop and if else decision statement , however I will post a solution that I suppose will run faster and will use only four variables. So here it goes...

    #include
    void main()
    {
    int a,b,c,d;
    printf("Enter four numbers of your choice");
    scanf("%d%d%d%d",&a,&b,&c,&d);
    a>b&&a>c?a>d?printf("%d",a):printf("%d" ,d):(b>c&&b>d)?printf("%d",b):c>d?printf("%d", c):printf("%d",d);
    }
    

提交回复
热议问题