DO-WHILE LOOP
# include
.................................
....................
...................................
/*do {
body...........
...............
}
while(condition);
*/
}
WHILE LOOP
while(condition) {
command........
}
Now i am taking some examples of do and while....and i am also telling you where to use it..
let make a program to print 10 numbers in ascending order and i am taking i=1.
# include
# include
void main()
{
int i=1;
do {
cout<
i++;
}
while (i<=10);
getch();
}
now many of you are thinking that why we are using do when we can perform this operation by just while loop. yes you are right but you can perform this all printing by "for" loop too but i just wanna tell you that my main motive is to explain how to use do-while loop.
Now qution arises :-
Q1 How do-while loop works?
Ans1 Do -> Use as a must work loop. In simple words we can say this loop will run one time we want it or not it does'nt make any difference.
Q2 How many programs use do-while loops?
Ans2 (a)Factorial->Program ( please try once on your own)
(b)Prime number->program
(c)Fabonic series ->Program
(d)Reverse Number->program
(e)Armstrong ->program
No comments:
Post a Comment