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

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