हिंदी माध्यम नोट्स
C++ : if Statement with program example in hindi , what is if statement in c++ language with explanation
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 करेगे |
Recent Posts
सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है
सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…
मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the
marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…
राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi
sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…
गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi
gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…
Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन
वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…
polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten
get all types and chapters polity notes pdf in hindi for upsc , SSC ,…