Decision making with if statement may be implemented in different forms depending on the complexity of conditions to be tested.The different forms are,
- Simple if statement
- if….else statement
- Nested if….else statement
- Using else if statement
Syntax
if(expression) { //Inside if Statement Are Executed } else { //Inside else Statement Are Executed } //Outside if...else block Statement Are Executed
Here, if the expression is true then if block statements are executed and after it directly outside if…else block statements are executed, otherwise else block statements are executed and after it directly outside if…else block statements are executed. It means if expression is false then else block statements are executed.
Example is below ::
#include <stdio.h> #include<conio.h> void main() { int x,y; clrscr(); x = 15; y = 13; if (x > y ) { printf("x is greater than y"); } else { printf("y is greater than x"); } getch(); }
OutPut
x is greater than y
It’s Done. Keep It Up Guys…