khoob study

Sunday, November 6, 2022

If else if statement in c language

                                  If else if in c language 

#If else if :-whe we have many choices in our program and we wants to choose one of them then we can write the program can same "if else if " statement .

The syntex of if else if :-

if ( condition )
{
// set of statement 
}
else if (condition)
{
//set of statement 
}
-
-
-
-
-
-
-
else if (condition)
{
-
-
-
}
else
{
-
-
}

--- here 1st of all condition is evaluated in if part . If condition is true then statement of set of statements are executed other wise cndition goes to next else if , we  are again condition is evaluated if condition is true then statement or set of ststements are executed other wise condition goes to next else if  ,it will be continue . If non of the condition is matched then there may be an else wich will be executed .

EXAMPLE :- 

PROGRAM:-

#include<stdio.h>
#include<conio.h>
main()
{
int a;
clrscr();
printf("choose any number from 0 to 9  ");
scanf("%d",&a);
if(a==1)
printf("u have entered one ");
else if(a==2)
printf("u have entered two");
else if(a==3)
printf("u have entered three");
else if(a==4)
printf("u have entered four");
else if(a==5)
printf("u have entered five");
else if(a==6)
printf("u have entered six");
else if(a==7)
printf("u have entered seven");
else if(a==8)
printf("u have entered eight");
else if(a==9)
printf("u have entered nine");
else if(a==0)
printf("u have entered zero");
getch();

}


Output:-

ener number 0 to 9   8
 you have enter eight 

No comments:

Post a Comment