if else Statement

Written By -

if-else statement

 

if else statement : In the if-else statement first the if statement is executed and if the expression in if is true then the statements enclosed in the parenthesis will get executed and if the condition is false it won’t.


Now, here we can use the else statement with if statement to execute the code within parenthesis when the if condition is false.

The if-else statement looks like this:

if(condition)
{
execute, when if condition is true;
}

else
{
execute, when if condition is false;
}

Example :

#include <stdio.h>

int main()
{
int num;
printf(“Enter a number: ”);
scanf(“%d”,&num);
if(num < 50)
{
printf(“Number is less than 50.”);
}
else
{
printf(“Number is greater than 50.”);
}
return 0;
}

Output :

Enter a number: 75 //Input
Number is greater than 50. //Output

[yuzo_views]



CopyRight © 2019

CopyRight © 2019