lundi 20 août 2018

Conditional statement in C with nested if else else if

Found this code in a book:

if(a > b)
    if(c > b) printf("one");
    else if(c == a) printf("two");
    else printf("three");
else printf("four");

The question was: The program will never print
a. one b. two c. three d. four

The correct answer is b. two

Here, I cannot understand why it will not print two, as in the condition given, c can equal a and c can be greater than b at the same time

Aucun commentaire:

Enregistrer un commentaire