if Statement
Written by
if Statement
- C language has three main type of decision making statements :
- 1. if statement
- 2. if-else statement
- 3. switch statementt
if statement : In C language the if keyword tells the compiler to check the condition enclosed in the parenthesis. If the condition inside the parentheses is true then then the statements are executed and if the condition inside the parenthesis is false then the statements are not executed and thus, skipped.
The if statement looks like this:
if(this condition is true) { execute this statement; }
Example :
#include <stdio.h>int main() { int num; printf(“Enter a number: ”); scanf(“%d”,&num); if(num < 50) { printf(“Number is less than 50.”); } return 0; }
Output :
Enter a number: 25 //Input Number is less than 50. //Output
In the above example, if the number is less than 50, than the statement will run else the printf statement will be skipped.