The if statement perform operation either condition is true or false.
If Statement
This statement execute the code if condition is true
if(condition) { Statements Condition True }
#include void main() { int a=20,b=10; if(a>b) { printf("%d Greater Is",a); } }
output:- 20
If-else statement
if-else statement execute the code if condition is true or false.
if(condition) { Statement Condition True } else{ Statement Condition False }
#include void main() { int n=2; if(n>0) { printf("Number Is Positive"); } else{ printf("Number Is Negative"); } }
output:- Number Is Positive
else-if statement
else-if statement is used to execute one code multiple conditions
if(condition) { Statement Condition True } else if(condition){ Statement Condition True } else if(condition){ Statement Condition True } else{ Statement Condition False }