If else if Statement in C Language

Hello friends how are you, today in this blog i will teach you what is if else if statement, syntax of if else if, how if else if statement works and many programs using if statement in a very simple way.

Let's start


1.It is a part of conditional statement that executes only one condition at a time.
2.If all conditions are false then else part executes.
3.It executes that condition that becomes first true from the top.
4.In the case of if in the place of condition always zero and non-zero value is checked in which zero means condition false and non-zero means condition true

👉Example 1 

int main()
//Assigning value to the variable
int x=10;
if(x>5)//checking the condition
printf("x is greater than 5");
else if(x<8)//checking the condition
printf("x is less than 8");
else if(x==10)//checking the condition
printf("x is equal to 10");
printf("No one condition is true");
### output ###
x is greater than 5

As we can see from the above program there are three conditions in which first and third condition are true but it executes only one condition that becomes first true from the above so the output is x is greater than 5

👉Program: Show result according to percent

First div  >=65
Second div between 64 and 45
Third div  between 44 and 33
Fail       <33
int main()
//variable declaration
float p;
//taking user input of percentage
printf("Enter your percentage:");
printf("First Division");
else if(p>=45)
printf("Second Division");
else if(p>=33)
printf("Third Division");
printf("Sorry! You are fail!!!");
### Output ###
Enter your percentage:85
First Division
Enter your percentage:30
Sorry! You are fail!!!

Request:-If you found this post helpful then let me know by your comment and share it with your friend.

If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all.

If you have not subscribed my website then please subscribe my website.

Try to learn something new and teach  something new to other.


Post a Comment