C If-else statement


C If-else statement

This statement has a single section, but it has two blocks.
One is true block and the other is false block.


In this condition is checked first. If it is true, then the program control flow goes inside
the braces and executes the block of statements associated with it. If it returns false,
then it executes the else part of a program.

Syntax :

if(condition)
{
true statements;
}
else
{
false statements
}


Example :


#include <stdio.h>
#include <conio.h>

void main()
{
int no;
clrscr();
printf("\n Enter Number :");

scanf("%d",&no);

if(no%2==0)
printf("\n\n Number is even !");

else
printf("\n\n Number is odd !");

getch();
}

Output :








When user enter 11 the if condition becomes false and hence the else statement is executed.

     Prev                                                   NEXT

0 comments:

Post a Comment