I was asked if I could write a code to find the biggest of the five numbers, rather than going with the conventional if...else
(can't use switch
or traversal - restricted) I decided to use compact version but IMO I found it verbose and confusing (tried it on three numbers first):
#include<stdio.h>
int main(void)
{
int a[3]={9,5,13};
printf("Biggest No. is: %d\n",(a[0]>
(a[1]>a[2]?a[1]:a[2])?a[0]:
(a[1]>a[2]?a[1]:a[2])));
return 0;
}
Now doing this thing with this method for five numbers seems disastrous, is there any way it can be made simpler (by using this compact method of ?:
only) as writing the expression which acts as a condition and writing it again as a result seems too much?
Or should I go with the conventional if ... else
block?
Found a thing: To use macro for one expression and use that macro as condition and result for another comparison.