The if statement is used to specify conditional execution of program statement, or a group of statements enclosed in braces. The general format of the statement is
if (condition)
{
program statements;
}
When an if statement is encountered, condition is evaluated and if its value is true .the statement is executed. The if statement execution can be understood by going through the following program
Consider the problem of finding out the biggest among two numbers. The problem decision, that is, the tasks include
The following chart illustrates the working of the if construct.
Example 2.2.
The following example demonstrates how the greatest among (wo numbers is determined using the if-construct.
#include <stdio.h>
int main()
{
int value1, value2, big;
printf ( "Enter the number values");
scanf ("%d%d ", &value1, &value2);
big = value1;
if (valuel1< value2)
big = value2;
printf ( "The bigger number is %d"" , big) ;
}