Computer Science, asked by enakshiroydpsnt, 19 days ago

How is if-else statement different from if-else-if ladder in a java program?

Answers

Answered by anshumanmishra2102
0

Answer:

Nested if()...else statements take more execution time (they are slower) in comparison to an if()...else ladder because the nested if()...else statements check all the inner conditional statements once the outer conditional if() statement is satisfied, whereas the if()..else ladder will stop condition testing once any of the if() or the else if() conditional statements are true.

An if()...else ladder:

#include <stdio.h>

int main(int argc, char *argv[])

{

int a, b, c;

printf("\nEnter Three numbers = ");

scanf("%d%d%d", &a, &b, &c);

if ((a < b) && (a < c))

{

printf("\na = %d is the smallest.", a);

}

else if ((b < a) && (b < c))

{

printf("\nb = %d is the smallest.", b);

}

else if ((c < a) && (c < b))

{

printf("\nc = %d is the smallest.", c);

}

else

{

printf("\nImprove your coding logic");

}

return 0;

}

Similar questions