Introduction
When you want to take actions based on the outcome of the conditions, (true or false), then you can use the if-else statement.
Program/Example
The general format for an if-else statement is
if (condition) simple or compound statement // s1 else simple or compound statement. // s2
If the condition is true then the s1 part is executed and if the condition is false then the s2 part is executed. For example,
if (a>b) printf (" big number is %d", a); // s1 else printf (" big number is %d", b); // s2
if a is greater than (b) then s1 is executed. Otherwise s2 is executed.
No comments:
Post a Comment