Tuesday, August 9, 2022

C Program to understand the concept of "if-else" statement in C by Satyam Srivastava

C Program to understand the concept of "if-else" statement in C by Satyam Srivastava

If-else Statement

The if-else statement is used to perform two operations for a single condition. The if-else statement is an extension to the if statement using which, we can perform two different operations, i.e., one is for the true condition, and the other is for the false. Here, we must notice that if and else block cannot be executed in same time. The syntax of the if-else statement is given below.

if(condition)

{  

//code to be executed if condition is true  

}

else

{  

//code to be executed if condition is false  

}  

Youtube Video

 Flow Chart

Sorce Code

//WAP to understand the concept of
//if-else statement
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
printf("Enter any number\n");
scanf("%d",&n);
if(n % 2 == 0)
{
printf("Even number");
}
else
{
printf("Odd number");
}
getch();
}

No comments:

Post a Comment