It can be
used to choose one block of statements from many blocks of statements. The
condition which is true only its block of statements is executed and remaining
are skipped.
Syntax:
if
(condition)
{
statement(s);
}
else if
(condition)
{
statement(s);
}
else
{
(statement);
}
Flow Chart
Flow Chart

Example:
#include<stdio.h>
#include<conio.h>
void main ()
{
int n;
clrscr();
printf("Enter a number:");
scanf("%d",&n);
if(n>0)
printf("The
number is positive.");
else if (n<=0)
printf("The
number is negetive.");
else
printf("The
number is zero.");
getch();
}
No comments:
Post a Comment