Skip to content

If – Else Statement

by yashan on September 28th, 2011

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.

From → C Tutorials

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS