AJ ham if else k bary me pharany gy es ko ham selection statement b kehty hai ye ham 2 way decision k lay use klarty hai agr if ke condition false ho gai to per else ke condition chalii ge….
syntx
if(condition)
…….
else
…………
ab ek program banaty hai
es me ham ek value user se input lainy gy ur daikain gy k ye 100 se bari hai choti ?
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n;
cin>>n;
if(n>100)
cout<<”n is greater than 100”;
else
cout<<”n is less than 100”;
getch();
}
Es me ham user se input lain gy jo k n me store ho jai ge per check kary ga agr value 100 se greater ho to if wali statement chali ge agr less hai to else wali statement chali ge faraz kary k user ne 101 de to output
n is greater than 100
aye ge
Ek ur program banty hai jes me ham check karny gy k user ne jo value de hai wo odd hai ya even hai
#include<iostream.h>
#include<conio.h>
void main()
{
int n;
cin>>n;
if(n%2==1)
cout<<”odd number”;
else
cout<<”even”;
getch();
}
es me user se value laian gay ur daikny gy wo value n me store ho jai ge ur per check ho ge agr n ka remander 1 aya to value odd ho agr 0 aya to even ho ge
ur ha programming jab comile hoti hai to line by line check hoti hai means k es program me pehly memory me ek jaga ka nam n rak dia jay ga per n ko value mil jai ge jo k cinn kia hai per if ke condition chali ge agr true ho to if ke output aye ge agr false hoa to if ko ignore kar k else ke chali ge ok
ab nested if else start karty hai
jab ap multi way decision check karty ho to us k lay ham nested if else use karty hai
means k ap k pass several room hai u rap dikty ho k ali konsy room me hai to es k lay ap nested if else use karty ho
ab ek program banty hai jes me ham 3 input user se lain gay ur check karny gy k equal hai ya nahe
#include<iostrem.h>
#include<conio.h>
void main()
{
float a,b,c
cin>>a>>b>>c;
if(a==b)
{
if(a==c)
cout<<”All value are equal”;
else
cout<<”value are different”;
getch();
}
es me ham user se float type ke value lain gy user se per check kary ga k value a==b k hai to true ho k 2 contion py jay ga k a==c b hai agr ha to ouput aye k All value are equal
agr a b k equal nahe hai to condition false ho jai per 2 condtion check ho ge agr 1 c k equal to result show ho ga k value are different q k 1 condition to flase ho gai hai na agr 1 equal ho ur 2 different to b else wali statement chali ge q k k ham ne dono conitionk lay lagya hai k a==b and a==c than show all value are equal got it …..
es tarha ap log khud se b practice kary
Thanks
Reg:: MT ALI OKZ
No comments:
Post a Comment