Do While Loop
Integers:
- #include<iostream.h>
- int main ()
- {
- int a;
- a=1;
- do
- {
- cout<<"\n"<<a;
- a=a+1;
- }
- while(a<=10);
- system("pause");
- return 0;
- }
Even Number:
- #include<iostream.h>
- int main()
- {
- int a;
- a=2;
- do
- {cout<<"\n"<<a;
- a=a+2;
- }
- while(a<=20);
- system("pause");
- return 0;
- }
Odd Numbers:
- #include<iostream.h>
- int main()
- {
- int a; a=1;
- do
- {cout<<"\n"<<a;
- a=a+2;
- }
- while(a<=21);
- system("pause");
- return 0;
- }
Reverse Number:
- #include<iostream.h>
- int main()
- {
- int a;
- a=10;
- do
- {cout<<"\n"<<a;
- a=a–1;
- }
- while(a>=1);
- system("pause");
- return 0;
- }
Print a name ten time:
- #include<iostream.h>
- #include<conio.h>
- int main()
- {
- int a;
- a=1;
- do
- {cout<<"\n"<<a<<"sagar";
- a=a+1;
- }
- while(a<=10);
- system("pause");
- return 0;
- }
Square and Cube:
- #include<iostream.h>
- int main()
- {
- int a;
- a=1;
- do
- {cout<<"\n"<<a<<"\t"<<a*a<<"\t"<<a*a*a;
- a++;
- }
- while(a<=20);
- system("pause");
- return 0; }
Table of Given Number:
- #include<iostream.h>
- int main()
- {
- int a,b;
- cout<<" enter a number=";cin>>a;
- b=1;
- do
- {
- cout<<"\n"<<a<<"*"<<b<<"="<<a*b;
- b++;
- }
- while(b<=20);
- system("pause");
- return 0;
- }
Factorial of given number:
- #include<iostream.h>
- int main()
- {
- int a,b,c;
- cout<<" Enter a number=";
- cin>>a;
- c=1;
- b=1;
- do
- {
- c=c*b;
- b++;
- }
- while(b<=a);
- cout<<"\n factorial="<<c;
- system("pause");
- return 0;
- }