Monday, 17 September 2012

If-else if statement



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



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