In this tutorial, you will learn how to execute the If Else statement in C programming language. I have explained with some real time examples of If Else programs.
In the below diagram, If the “IF” condition satisfy, then IF statement will execute otherwise Else statement will execute and display the output of your program.
Below is the standard example of IF Else statement in C programming language:
1 2 3 4 5 6 7 8 | if(condition) { //write your code } else { //write your code } |
Real time example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include<stdio.h> main() { int a,b; printf("Please enter the value for a:"); scanf("%d",&a); printf("\nPlease the value for b:"); scanf("%d",&b); if(a>b) { printf("\n A is greater than B"); } else { printf("\n Bb is greater than A"); } } |
Output will be:
After executing the above program, you will see the below output.
1 2 3 4 | Please enter the value for a: 5 Please enter the value for b: 10 B is greater than A |
Also Read:
C Program: Find The Sum of Two Numbers
Prime Number Program in C Programming Language
Reverse Number Program in C
How to Compile and Run a C Programs
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: c tutorials, if and else statements in c, if else in c, if else statement c, if else statements c, if else statements in c