JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: c++ language in hindi

C++ : Nested if और switch Statement with program example explanation in hindi , what is Nested if and switch Statement

what is Nested if and switch Statement , C++ : Nested if और switch Statement with program example explanation in hindi :-
C++ language मे , c language के तरह switch statement को भी use किया जाता है | switch statement भी braching statement मे include होता है | जब किसी multiple condition को check किया जाता है | तब if statement का nested हो सकता है | सबसे पहले if statement के nesting को discuss करेगे | और बाद मे switch स्तातेम्न्त को discuss करेगे |Nesting if statement
जब दो या दो से अधिक condition को check किया जाता है | तब if statement के nesting को use किया जाता है | if statement के nesting को निन्म syntax को use किया जाता है |
if (condition 1)
{
body 1 ;
}
elseif(condition 2 )
{
body 2 ;
}
elseif(condition 3 )
{
body 3 ;
}
……………….
……………….
……………….
elseif(condition n )
{
body n;
}
else{
body n;
}
यहा पर
condition 1 ; ये condition 1 को check किया जाता है |
condition 2; ये condition 2 को check किया जाता है |
condition 3 ; ये condition 3 को check किया जाता है |
condition 4 ; ये condition 4 को check किया जाता है |
…………………………………….
…………………………………….
condition n ; ये condition n  को check किया जाता है |
जब condition 1 true होगी तब body 1 को execute किया जाता है | अन्यथा  condition 2 को check किया जाता है |
जब condition 2 true होगी तब body 2 को execute किया जाता है | अन्यथा  condition 3 को check किया जाता है |
जब condition 3 true होगी तब body 3 को execute किया जाता है | अन्यथा  condition 4 को check किया जाता है |
ये loop तब तक चलता है | जब तक condition n को check किया जाता है |
जब condition  true होगी तब body n को execute किया जाता है | अन्यथा  body n execute होता है |

इसका उदाहरन होता है :-
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
int a,b,c;
cout<<“Enter Value 1 ” :
cin>>a;
cout<<“Enter Value 2 ” :
cin>>b;
cout<<“Enter Value 3 ” :
cin>>c;
if(a>b)
{
if(a>c)
cout<<“Maximum Value :”<<a;
else
cout<<“Maximum Value :”<<c;
}
elseif(c>b)
{
cout<<Maximum Value :”<<c;
}
else
{
cout<<Maximum Value :”<<b;
}
getch();
}
इस उदाहरन मे , तीन values मे maximum value को find करते है | इसमें
सबसे पहले a>c की condition को check किया जाता है | और अगर condition true होती है तब a>c की condition की check की जाती है | अगर condition true होती है तब  maximum value : a display होती है | और  maximum value : c display होती है |
अन्यथा c>b की condition check की जाती है | अगर condition true होती है तब  Maximum Value :c print होगा | अन्यथा Maximum Value :b display होगा |

Switch statement
किसी प्रोग्राम मे multple condition को check करने के लिए nested if statement के अलावा switch statement को use किया जा सकता है | switch statement का syntax होता है :-
switch ( case_lable )
{
case case_lable 1 : body 1 ;
break ;
case case_lable 2 : body 2 ;
break ;
case case_lable 3 : body 3 ;
break ;

case default      : body  ;
break ;
}

switch statement निन्म keyword होते है :
case lable  : ये case lable है जो की condition के true होने पर body को पेर्व्फोर्म किया जाता है |
case_lable 1 : ये condition की value होती है जो की body 1 को perform करता है  |
case_lable 2 : ये condition की value होती है जो की body 2 को perform करता है  |
case_lable 3 : ये condition की value होती है जो की body 3 को perform करता है  |
switch statement मे default case को जरुर लिखना चाहिए |अगर condition मे मे से कोई भी value प्राप्त होती है तब default case मे लिखा  body perform होता है |
यहा case _lable किसी excpression का आउटपुट हो सकता है | या condition की value भी हो सकती है |
उदाहरन के लिए :
int a<b ; इस statement से दो case हो सकते है  ‘1’ या ‘0’ होगी |
और
a+b ; यह पर variable a और b की addition से आउटपुट मिलता है | इस आउटपुट  को switch statement मे case lable को बनाया जाता है |
इसका उदाहरन होता है :
इसका उदाहरन होता है :-
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char choice ;
int a,b,c ;
cout<<“Enter ‘a’ for addition “;
cout<<“Enter ‘s’ for subtraction”;
cout<<“Enter ‘m’ for multiplication “;
cout<<“Enter ‘d’ for divide “;
cout<<“Enter Choice  : “;
cin>>choice ;
cout<<“Enter Input 1 :  “;
cin>>a;
cout<<“Enter Input 2 : “;
cin>>b;
switch(choice)
{
case ‘a’ :
c=a+b;
break;
case ‘s’ :
c=a-b;
break;
case ‘m’ :
c=a*b;
break;
case ‘d’ :
c=a/b;
break;
defalut :
break;
}
cout<<“Output : “<<c;
getch();
}
getch();
}
इस उदाहरन मे यूजर द्वारा choice को input किया जाता है |अगर यूजर द्वारा input किया गया input निन्म होता है तब
‘a’ : variable ‘a’ और ‘b’ मे addition perform होता है |
‘s’ : variable ‘a’ और ‘b’ मे subtraction perform होता है |
‘d’ : variable ‘a’ और ‘b’ मे divind perform होता है |
‘m’ : variable ‘a’ और ‘b’ मे multiplication perform होता है |

इदका आउटपुट होगा :-
Enter ‘a’ for addition
Enter ‘s’ for subtraction
Enter ‘m’ for multiplication
Enter ‘d’ for divide
Enter Choice  : a
Enter Input 1 : 12
Enter Input 2 : 23
Output : 35

इस article मे nested if statement और switch statement को discuss किया है | अब अगले article मे switch statement पर based कुछ और उदाहरनो को discuss करेगे |

Sbistudy

Recent Posts

Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic

Question Tag Definition • A question tag is a small question at the end of a…

2 weeks ago

Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)

Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…

2 weeks ago

Report Writing examples in english grammer How to Write Reports explain Exercise

Report Writing • How to Write Reports • Just as no definite rules can be laid down…

2 weeks ago

Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th

Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…

2 weeks ago

विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features

continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…

2 weeks ago

भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC

भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…

2 weeks ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now