If statement in C programming allows you to control and execute a specific block of code if the condition is true or false based on some specific condition.
if(this condition is true)
execute this statement;
this expression | is true if |
---|---|
x == y | x is equal to y |
x != y | x is not equal to y |
x < y | x is less than y |
x > y | x is greater than y |
x <= y | x is less than or equal to y |
x >= y | x is greater than or equal to y |
#include<stdio.h>
#include<conio.h>
void main()
{
int num;
printf("Enter a number less than or equal to 10: ");
scanf("%d", &num);
if(num <= 10) //if 'num' value Less then or Equal to 10 then
{
printf("What an obedient servant you are!"); //print this.
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int num;
printf("Enter a number less than 10: ");
scanf("%d", &num); //user enter value storing in 'num'.
if(num < 10) //if 'num' value is less then 10 then
{
printf("Entered value is Less then 10!"); //print this.
}
if(num == 10) //if 'num' value is equal to 10 then
{
printf("Entered value is Equal to 10!"); //print this.
}
if(num > 10) //if 'num' value greater then 10 then
{
printf("Entered value is Greater then 10"); //print this.
}
getch();
}