JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi sociology physics physical education maths english economics geography History

chemistry business studies biology accountancy political science

Class 12

Hindi physics physical education maths english economics

chemistry business studies biology accountancy Political science History sociology

Home science Geography

English medium Notes

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Class 12

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

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

four potential in hindi 4-potential electrodynamics चतुर्विम विभव किसे कहते हैं

चतुर्विम विभव (Four-Potential) हम जानते हैं कि एक निर्देश तंत्र में विद्युत क्षेत्र इसके सापेक्ष…

2 days ago

Relativistic Electrodynamics in hindi आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा

आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा Relativistic Electrodynamics in hindi ? अध्याय : आपेक्षिकीय विद्युतगतिकी…

4 days ago

pair production in hindi formula definition युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए

युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए pair production in hindi formula…

7 days ago

THRESHOLD REACTION ENERGY in hindi देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा

देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा THRESHOLD REACTION ENERGY in hindi…

7 days ago

elastic collision of two particles in hindi definition formula दो कणों की अप्रत्यास्थ टक्कर क्या है

दो कणों की अप्रत्यास्थ टक्कर क्या है elastic collision of two particles in hindi definition…

7 days 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