If Else Condition in C Programming
Hey Friends, in day-to-day life people take a lot of decisions by themselves. For ex:-
1. If it rains today, then I will not go to college
If not then I will go
2. If the train is late, I will catch the train
If not, I will not be able to get the train
Taking decisions in programming is an important part of it. C language also uses decision instruction. In C Programming there are mainly 3 types of decision control instruction
1. If
2. If-else
3. Switch
Till now we have studied sequence control instruction. In that instruction, Statements are executed in the order in which they have written or appear. But During the high-level projects, we need to execute a set of instructions by conditions. If the first condition is true then code will run or if the condition is not true (false) then the other condition runs or execute.
So the selection of the condition (true or false) of instructions is called Decision.
Now, In this article, we gonna learn about decision control instruction.
If Statement in C programming
In C programming, (if) is a keyword to execute an instruction if the instruction is true. In Simple World, if the given condition is true your code will be run. If not then the code didn’t run.
The Syntax of the if the condition was given below:-
If (condition)
{
Statement 1;
Statement 2;
Statement 3;
}
Let us Check through an example :-
#include <stdio.h>
int main()
{
int a;
printf("Enter the Number = ");
scanf("%d", &a);
if (a<=10)
{
printf("A is Smaller than 10");
}
return 0;
}
Output:-
Look at the function of the code:-
• In this program, we take a numeric input from the user to check whether a number is greater than 10 or smaller than 10.
• If the numerical number is smaller than 10. Then the output will display a message to the user that your input is smaller than 10.
• But if the number is greater than 10. Nothing will be shown on the display. Because we give only one statement in this program.
So that’s all for today guys.. we will continue the rest of the function in the next part of the article. if you have any query related to this comment below.
Your website is terribly informative and your articles are wonderful.
ReplyDeletebest web design firms