Conditional Statements Operations in C Language
Simple if statement in C Language
If Statement: If the condition is true its body executes otherwise does not execute. In the case of if in the place of condition always zero and non-zero value is checked in which zero means condition false and non-zero means condition is true.
C, the if statement is used to conditionally execute a block of code based on the value of a given expression.
If-Else Statement|Conditional Operations in C Language |
if(condition) { //Statements; } |
#include<stdio.h> #include<conio.h> void main() { int x=50; int y=20; if(x>y) { printf("x is greater than y"); } getch(); } **********OUTPUT********** x is greater than y |
Choose a statement to use if else statement in C Language
if(condition) { //Statements; } else { //Statements; } |
#include<stdio.h> #include<conio.h> void main() { int x=50; int y=20; if(x==y) { printf("x is greater than y"); } else { printf("x is not greater than y"); } getch(); } **********OUTPUT********** x is not greater than y |
Explain if else if ladder statement with syntax and example
if(condition) { //Statements1; } else if(condition) { //Statements2; } else if(condition) { //Statements3; } else() { //Statements4; } |
#include<stdio.h> #include<conio.h> void main() { int x=10; if(x>5) { printf("x is greater than 5"); } else if(x<8) { printf("x is less than 8"); } else if(x==10) { printf("x is equal o 10"); } else { printf("No one condition is true"); } getch(); } **********OUTPUT********** x is greater than 5 |
Nested if statement in C Language with example
if(condition) { if(condition) { //Statements1; } } |
#include<stdio.h> #include<conio.h> void main() { int x=50; if(x>5) { if(x<15) { printf("x is greater than 5 and less than 15"); } } getch(); } **********OUTPUT********** x is greater than 5 and less than 15 |
Switch Statement in C Programming Language
switch(condition) { case 1: statement1; break; case 2: statement2; break; case 3: statement3; break; case n: statement n; break; default: default statement; } |
#include<stdio.h> #include<conio.h> void main() { int s=2; switch(2) { case 1: printf("Case 1 will be executed"); break; case 2: printf("Case 2 will be executed"); break; case 3: printf("Case 3 will be executed"); break; default: printf("Case are not match"); } getch(); } **********OUTPUT********** Case 2 will be executed |
0 Comments