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

后端 未结 18 2498
北海茫月
北海茫月 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 12:05

    This is too easy, given that the numbers are a,b,c,d:

    #define min(a,b)  ((a) < (b) ? (a) : (b))
    #define max(a,b)  ((a) > (b) ? (a) : (b))
    biggest  = max (max(a,b), max(c,d))
    smallest = min (min(a,b), min(c,d))
    

    Here you go, no if statements, no functions (though the latter is the most stupid and harmful to adepts requirement I ever heard of).

提交回复
热议问题