If( test expression )
Statement block if TRUE
If( test expression )
{
Statement block if condition TRUE
}else{
Statement block if condition False
}
#include <stdio.h>
int main(void){
int num1;
printf("Enter the number ");
scanf("%d",&num1); // Enter numbers
if(num1 <= 10)
{
printf(" Your number is less than or equal to ten");
}
else
{
printf(" Your number is more than ten"); // printng outputs
}
return 0;
}
#include <stdio.h>
int main(void){
int num;
printf("Enter a number less then or equal to 100 : ");
scanf("%d",&num);
if(num >= 80)
printf(" First Division " );
else {
if(num>= 60){
printf(" Second Division ");
}else{
if( num>=40){
printf(" Third Division ");
}else{
printf(" Fail ");
}
}
}
return 0;
}
if(expression is true){
// statement to execute
}
else if ( expression is true){
// statement to execute
}else if ( expression is true){
// statement to execute
}
else {
// final statement to execute if nothing is ture
}
Example
int main()
{
int x=20;
if(x>=30){
printf(" I am greater than or equal to 30 \n");
}else if(x<20){
printf(" I am less than 20 \n");
}else
printf("I am greate than or equal to 20 but less than 30 \n");
}
Check the grade of the student by using else if condition
Highest of three user input numbers
Different tariff plan for different range of consumption (Example of if else )18-08-2023 | |
Write an if-else statement to check if the grade is above or equal to 60 |