C Programming में Statement के सात प्रकार है
- if Statement
- if_else Statement
- else_if Statement
- switch case Statement
- break Statement
- continue Statement
- goto Statement
1. if Statement
- if Statement में अगर Condition true होती है तब Statement Execute होता है |
Syntax for if Statement
if(condition){statement(s);
}
for eg.
int a=10, b=20;
if( a < b ){
printf("a is less than b");
}
Example for if Statement
Source Code :
#include <stdio.h>
int main(){
int a=10, b=20;
if (a < b)
{
printf("a is less than b");
}
return 0;
}
Output :
a is less than b
2. if_else Statement
- if_else Statement में अगर Condition true हो तो वो if का statement Execute करता है | अगर Condition false होती है तो else का statement execute करता है |
Syntax for if_else Statement
if(condition){statement(s);
}else{
statement(s);
}
for eg.
int a=10, b=20;
if( a == b ){
printf("a is equal to b");
}else{
printf("a is not equal to b");
}
Example for if_else Statement
Source Code :
#include <stdio.h>
int main(){
int a=10, b=20;
if( a == b ){
printf("a is equal to b");
}else{
printf("a is not equal to b");
}
return 0;
}
Output :
a is not equal to b
3. else_if Statement
- else_if Statement में अगर if की Condition true होती है तो if का statement execute होता है | अगर if का condition false होता है तो वो अगले condition पर जाकर check करता है | अगर वो condition true होता है तो वो उसका statement execute करता है | अगर कोई भी condition true नहीं होती तो वो else का statement execute करता है |
Syntax for else_if Statement
if(condition){statement(s);
}else if(condition){
statement(s);
}else{
statement(s);
}
for eg.
int a=10, b=20;
if( a < b ){
printf("a is less than b");
}else if( a > b ){
printf("a is greater than b");
}else{
printf("a is equal to b");
}
Example for else_if Statement
Source Code :
#include <stdio.h>
int main(){
int a=10, b=20;
if( a < b ){
printf("a is less than b");
}else if( a > b ){
printf("a is greater than b");
}else{
printf("a is equal to b");
}
return 0;
}
Output :
a is less than b
4. switch case Statement
- Switch case statement में expression होता है और उससे related कुछ cases होते है | जो case उस expression या declare किये हुए variable से match होती है तब वो output में print होता है | अगर कोई भी case expression से match नहीं होती तो वो default का statement output में print करेगा | आपको हर statement के बाद break लगाना पड़ता है, इसका मतलब वो उसके पहले का statement ही print करेगा | अगर आप break नहीं लगाते तो वो पहला और दूसरा ये दोनों statement को print करेगा | default case के बाद break नहीं लगाते |
Syntax for switch Statement
switch (expression){case value1 :
statement1 ;
break;
case value2 :
statement2 ;
break;
default :
statement3 ;
}
Example for switch Statement
Source Code :
#include <stdio.h>
int main(){
char Day='D';
switch(Day){
case 'A' :
printf("\nToday is Sunday");
break;
case 'B' :
printf("\nToday is Monday");
break;
case 'C' :
printf("\nToday is Tuesday");
break;
case 'D' :
case 'E' :
printf("\nToday is Wednesday");
break;
case 'F' :
printf("\nToday is Thurday");
break;
case 'G' :
printf("\nToday is Friday");
break;
case 'H' :
printf("\nToday is Saturday");
break;
default :
printf("\nDay is Not Found");
}
return 0;
}
Output :
Today is Wednesday
5. break Statement
- Break Statement Program के loops और switch case के execution का काम किसी condition पर बंद कर देता है |
Syntax for break Statement
break;Example for break Statement
Source Code :
#include <stdio.h>
int main()
{
int i=0;
while ( i < 20 ){
printf("value of i is %d\n", i);
i++;
if ( i == 10)
break;
}
return 0;
}
Output :
value of i is 0 value of i is 1 value of i is 2 value of i is 3 value of i is 4 value of i is 5 value of i is 6 value of i is 7 value of i is 8 value of i is 9
6. continue Statement
- Continue Statement Program के loops के condition के हिसाब से बीचवाले statements को skip कर देता है और बादवाले statement को execute करता है |
Syntax for continue Statement
continue;Example for continue Statement
Source Code :
#include <stdio.h>
int main(){
int i;
for(i=0;i<10;i++)
{
if(i==7)
{
printf("Number %d is skipped.\n",i);
continue;
}
printf("%d\n",i);
}
return 0;
}
Output :
0 1 2 3 4 5 6 Number 7 is skipped. 8 9
7. goto Statement
Go to ये C Programming का statement है | इसमें labels का use किया जाता है |Goto Statement के दो प्रकार होते है |
- Forward
- Backward
Syntax for Forward and Backward goto Statement
Syntax for Forward
goto label ;statement ;
-----------
label ;
Syntax for Backward
label ;statement ;
-----------
goto label ;
Example for goto Statement
Source Code :
#include <stdio.h>
int main(){
int num1, num2, num3;
char ch;
yes : printf("Enter two values\n");
scanf("%d%d",&num1, &num2);
num3 = num1 + num2 ;
printf("Addition of %d and %d is %d\n", num1, num2, num3);
printf("\nDo you want to continue y(yes) or n(No)");
scanf(" %c",&ch);
if(ch=='y'){
goto yes;
}
else if(ch=='n'){
goto no;
}
else{
printf("You entered other key");
}
no : printf("Do you want to exit ?, Press Enter");
return 0;
}
Output :
Enter two values 5 9 Addition of 5 and 9 is 14 Do you want to continue y(yes) or n(No)y Enter two values 5 8 Addition of 5 and 8 is 13 Do you want to continue y(yes) or n(No)







No comments: