If Else Statement With Example - C Programming

Explain If Else Statement With Example In C Programming With Code
\\ If you have any query or questions on my post, then please comment below //

What is If Else Statement: 
If else is a statement which provide the facility like " Using Or Evaluating True Or False Value". In if statement, we are using only one statement, here we are printing or evaluating only true part of the statement. We can't print or evaluate the false condition. So if we want to work on false condition, Then it's not possible. So for avoiding this problem if else statement occurs. If Else Statement is widely used for printing or evaluating the true and false part of any statement.

Example of If Else Statement:
Suppose we are having a statement like: 
Write a program to print a message according to used input. If user input is 1 then print a message " Welcome To Technical Programming - Thanks!!". And if he enters any other number then print a message "Please Try Again".
So here you see program is divided into 2 parts:
First: If user input is 1 then print a message " Welcome To Technical Programming - Thanks!!".
Second:  If he enters any other number then print a message "Please Try Again".

First part of the program is truly part and second part of the program is false part, Because if user input any other number than 1 then print the message"Please Try Again". Now I hope you understand if else statement very well.

Syntax Of If Else Statement:

  if (test_condition)
  {
  -----------------------
  -----------------------   // True Part or True Statement
  }   
  else 
  {
  -----------------------
  -----------------------   // False Part or False Statement
  } 
Now Example Of If Else Statement In C Programming: 
I am taking the above mentioned question 
-------------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("Enter A Number:");
scanf("%d",&a);           
if (a==1)                                    // Check input number is 1, if 1 then only program execution, enter in
  {                                              //if block, otherwise move to false block (else block).
    printf("Welcome To Technical Programming - Thanks!!");  
  }
else                                          // If statement is false, then program automatically enter to else block.
 {
  printf("Please Try Again");
 }
}   
------------------------------------------------------------------------------------

If you have any query then feel free to contact with us, or comment below if you found any error in the above code.
 
Click Here To Know How To Download Above Video Tutorials Or YouTube Videos Free


 Enter Your Email Id To Get Our Programming, Web Development, Video Tutorial, Job Updates In Mail:

Labels: