If – Else Statement

In C programming language the if  – else is one of the branching and the decision making statements The If – else statement is an extension of the simple if statement. The general form is –

if (test expression)
{
     True block statement(s)
}
else
{
     False-block statement(s)
}
statement-x


If the test expression is true, then the true block statement(s), immediately following the if statements are executed; otherwise , the false block statement(s) are executed. In either case, either true block or false block will be executed, not both. In both cases, the control is transferred subsequently to the statement-x as this statement as no link with the if else statements.

Below is the sample program of how to use the If -Else statements and to find if the number is greater than 100 or not –

#include<stdio.h>
void main()
{
     int n;
     
     printf("Enter any number \n");
     scanf("%d",&n);
     
     if(n<100)
     {
         printf("%d is less then 100",n);
     }
     else
     {
         printf("%d is greater then 100",n);
     }
     getch();
}

In the above program if the number inputted is less than 100 then the if block (True block statement) will be executed and if the number inputted is greater than 100 then the else block(False block statement) will be executed.

yashan has written 70 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>