C++ Lecture 11 In Urdu
While loop
practice
#include<iostream>
#include<conio.h>
void main()
{
int a;
cout<<"Enter the Number
:";
cin>>a;
int c=1;
while (c <= a)
{
cout<<"Execute
While "<<c<<" time"<<endl;
c++;
}
Cout<<”Mt Ali
okz”;
getch();
}
·
Pehly ham ne int type ka variable liya jes ko ham
ne a ka name assign kia
·
Per user se us ke value lain gy jo k user int
type ka dy ga
·
Per int type ka c liya ur 1 se initilize kia c
counter k lay kam kary ga
·
Per while ke conndition lagi
·
Condition check ho ge farz kary k user ne a ko 3
value de hai
·
C ke value 1 hai to condition true hai q k 1 less
hai 3 se
·
Body me aye ga cout ke statement execute ho ge
·
Execute while 1 time aye ga line change ho jai ge
·
C me increment ho ge 2 ho jai ge
·
Oper jai ge condition check ho ge
·
2<=3 to ture hai
·
Body me aye ge
·
Cout ke satement execute ho ge
·
Execute while 2 time aye ga line changew ho jay
ga
·
C me increment ho jai ge 3 ho jay ga
·
Oper jay ga condition check ho ge
·
3<=3 true hai q k equl to hai na
·
Body me aye ga cout ke ststement execute ho ge
·
Execute while 3 time line change ho jai ge
·
C me increment ho ga 4 ho jay ga
·
Condtion check ho ge to false ho jay ga q k 4
greater hai 3 se
·
Body se bahar ajy ga .
·
Next staement chali Mt Ali okz wali ou output ye
aye ge
Execute while
1 time
Execute while
2 time
Execute while
3 time
Mt Ali okz
#include<iostrem.h>
#include<conio.h>
void main()
{
int tab,res,c;
cin>>tab;
c=1;
while(c<=5)
{
res=tab*c;
cout<<tab<<”*”<<c<<”=”<<res<<endl;
c++;
}
cout<<”multiplication
table”;
getch();
}
·
Es me ham multiplictaion ka table bany gy
·
3 varibale lle hai int type ke tab ,res, c
·
Tab use for table jes ka ham table bany gy farz
kary k user ne 5 ka bana hai to user ne 5 input dia
·
Res use for result.
·
C use for count e.g 1,2,3,4 etc ur 1 se
initialize kai
·
Condition chali ge while ke c less hai ya equl 5
k to less hai q k c 1 hai
·
Body me aye ga
res=tab*c ho ga res=5*1
·
Next staement chali ge 5*1=5 ho ga line change ho
jai ge
·
C me increment ho ge c ke value 2 ho jai ge oper
jay ga condtion check ho ge
·
]condtion true hai q k 2 less hai 5 se
·
Body me aye ga res=5*2
·
Next staement 5*2=10 ho line change ho ge
·
C me increment ho ge 3 ho jay ga
·
Es tarhqa ho ga per c ke value 5 ho ge to chali
ge q k true hai q k ham ne condition lagi hai less ho ya equl to equal hai
·
Per increment ho ge to c ke value 6 ho jai ge
condtion false ho jai ge ur while k body se bahr aye
·
Next satement chali ge
·
multiplication table
output
5*1=5
5*2=10
5*3=15
5*4=20
5*5=25
multiplication table
5*2=10
5*3=15
5*4=20
5*5=25
multiplication table
To aj k lay itna kafi ta agy InshAllah es k bad
do-while start karain gy
Reg:Mt Ali O kz
No comments:
Post a Comment