JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: c++ language in hindi

C++ : if Statement with program example in hindi , what is if statement in c++ language with explanation

what is if statement in c++ language with explanation , C++ : if Statement with program example in hindi :-
इससे पहले के article मे loop , data type , operator को discuss किया जाता है | लेकिन अभी तक हमने braching statement को discuss नहीं किया है | अब इस article मे इन्ही   braching statement को discuss करेगे |जब किसी c++ language desicion लेना होता है तब  braching statement को use किया जाता है | या किसी loop मे लगातार चलने के लिए  braching statement को use किया जाता है |  braching statement को दो भागो मे डिवाइड किया जाता है :-

If Statement
जब किसी c++ प्रोग्राम मे किसी statement को perform करने के लिए if statement को use किया जाता है | if statement को दो प्रकार से use किया जाता है  | if statement और if-else statement | if statement मे condition को लिखा जाता है | अगर condition true होता है तब true statement को perform किया जाता है | अन्यथा false statement perform होता है |
अतः if statement को किसी statement को perform करने के लिए किया जाता है | इसका syntax होता है :
if(condition )
{
true statement body
}
false statement body

यहा पर
condition को check किया जाता है | अगर  condition true होती है तब true statement को perform किया जाता है अन्यथा false statement को perform किया जाता है |
अगर  condition true होती है तब इस statement का आउटपुट ‘1’ होती है अन्यथा इस statement का आउटपुट ‘0’ होती है |
इसका उदाहरन होता है :-
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
int a;
cout<<“enter Number :”;
cin>>a;
if(a%2==0)
{
cout<<“number is even .”;
}
cout<<“number is not even.”;
getch();
}
इस उदाहरन मे even की condition को check किया जाता है | अगर number % 2 का remainder ‘0’ होगा तब number is even. display होगा | अन्यथा  number is not even. display किया जाता है |
इसका आउटपुट होगा :
enter Number : 23
number is not even.

उदहारण -2 :
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
int a;
cout<<“enter Number :”;
cin>>a;
if(a%2!=0)
{
cout<<“number is odd .”;
}
cout<<“number is not odd.”;
getch();
}
इस उदाहरन मे even की condition को check किया जाता है | अगर number % 2 का remainder ‘0’ नहीं  होगा तब number is odd . display होगा | अन्यथा  number is not odd. display किया जाता है |
इसका आउटपुट होगा :
enter Number : 23
number is odd .

if – else statement
जब किसी c++ प्रोग्राम मे किसी statement को perform करने के लिए if-else statement को use किया जाता है |  if else statement मे condition को लिखा जाता है | अगर condition true होता है तब true statement को perform किया जाता है | अन्यथा false statement perform होता है |
अतः if else statement को किसी statement को perform करने के लिए किया जाता है | इसका syntax होता है :
if(condition )
{
true statement body
}
else
{
false statement body
}

यहा पर
condition को check किया जाता है | अगर  condition true होती है तब true statement body को perform किया जाता है अन्यथा else block मे लिखी false statement body  को perform किया जाता है |
अगर  condition true होती है तब इस statement का आउटपुट ‘1’ return होती  है अन्यथा इस statement का आउटपुट ‘0’ return होती है |
इसका उदाहरन होता है :-
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
int a;
cout<<“enter Number :”;
cin>>a;
if(a%2==0)
{
cout<<“number is even .”;
}
else
{
cout<<“number is odd.”;
}
getch();
}
इस उदाहरन मे even की condition को check किया जाता है | अगर number % 2 का remainder ‘0’ होगा तब number is even. display होगा | अन्यथा  number is odd . display किया जाता है |
इसका आउटपुट होगा :
enter Number : 23
number is odd .

आगे के article मे braching statement पर based कुछ और उदाहरनो को discuss करेगे :-
उदाहरन -3
इस उदाहंर मे किसी array मे सबसे से बड़े element value को find किया जाता है | इसके लिए array को declare किया जाता है | इसमें यूजर द्वारा element को assign किया जाता है |
उसके बाद loop की जाती है |
जिसमे max = array के first element को assign किया जाता है \ उसके बाद इअका compare array के दुसरे element किया जाता है |
अगर max की value second value से छोटी होती है तब max और second value को interchange किया जाता है | और max value को तीरसे value से compare किया जाता है |
अगर max की value second value से बड़ी  होती है और max value को तीरसे value से compare किया जाता है |
ये loop तब तक चलता है array का end नहीं हो जाता है |
उसके बाद max की value को display किया जाता है |
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5] ,max,i,temp ;
cout<<“Enter values :”;
for(i=0;i<5;i++)
{
cin>>a[i];
}
max=a[0];
for(i=0;i<5;i++)
{
if(max > a[i])
{
temp = a[i];
a[i]=max;
max=temp;
}
cout<<“Maximum number ;”<<max;
}
getch();
}

उदाहरन -4
इस उदाहंर मे किसी array मे सबसे से छोटी  element value को find किया जाता है | इसके लिए array को declare किया जाता है | इसमें यूजर द्वारा element को assign किया जाता है |
उसके बाद loop की जाती है |
जिसमे min  = array के first element को assign किया जाता है |उसके बाद इसका compare array के दुसरे element किया जाता है |
अगर min की value second value से बड़ी  होती है तब max और second value को interchange किया जाता है | और min value को तीरसे value से compare किया जाता है |
अगर min  की value second value से छोटी  होती है और min value को तीरसे value से compare किया जाता है |
ये loop तब तक चलता है array का end नहीं हो जाता है |
उसके बाद max की value को display किया जाता है |
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5] ,min ,i,temp ;
cout<<“Enter values :”;
for(i=0;i<5;i++)
{
cin>>a[i];
}
min = a[0];
for(i=0;i<5;i++)
{
if(min > a[i])
{
temp = a[i];
a[i]=min;
min =temp;
}
cout<<“Minimum number ;”<<min ;
}
getch();
}

इस article मे if statement को discuss किया गया है अब आगे के article मे switch statement को discuss करेगे |

Sbistudy

Recent Posts

मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi

malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…

4 weeks ago

कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए

राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…

4 weeks ago

हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained

hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…

4 weeks ago

तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second

Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…

4 weeks ago

चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi

chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…

1 month ago

भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi

first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…

1 month 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