![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Either the if-true statement or the if-false statement or both may be
embedded if
statements. Accordingly, another solution to the
ratio-testing problem looks like this:
#includemain ( ) { int ratio; scanf ("%i", &ratio); if (ratio < 10) printf ("It is cheap!\n"); else if (ratio > 30) printf ("It is expensive!\n"); }
Note that the first if
statement's if-false statement is, itself, an
embedded if
statement:
if (ratio > 30) printf ("It is expensive!\n");
This second if
statement is executed only if the ratio is not
less than 10. If the ratio is between 10 and 30, nothing is displayed.