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 Statement Are Executed } //Outside Statement Are Executed
Here, If the expression evaluated as true then inside statements are executed, otherwise outside statements are executed.
If the if block has only one statement then there is no need to put curly braces {}, but if the if block has more then one statement then it must put curly braces.
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"); } getch(); }
OutPut
x is greater than y
It’s Done. Keep It Up Guys…