The
if statement by itself will execute the single statement or a group of
statement when the expression following ‘if’ evaluates true.It does
nothing when the expression evaluates to false. To overcome this problem
,we use else statement, which is evaluated when expression within if evaluates to false.
Syntax-
-------------
-------------
if(expression)
{
------------
------------
}
else
{
------------
------------
}
------------
------------
When
expression within if evaluates to true, statements within the body of
if are executed .Otherwise statements within body of else are executed.
Example-
/*Demonstration of if-else statement */
#include<stdio.h>
int main()
{
int n=20;
if(n>20)
{
printf("Number is greater than 20.");
}
else
{
printf("Number is less than 20.");
}
return 0;
}
0 comments:
Post a Comment
Hey this is a test comment