Perulangan dengan 3 masalah di bawah ini kita selesaikan dengan FOR, WHILE DAN DO WHILE :
- 123456789
- 2468
- 1357
- 123456789
1. FOR
#include
#include
void main()
{ int x;
for(x=1; x<10 br="" x=""> cout<getch(); 10>
}
2.WHILE
#include
#include
void main()
{ int x;
while(x<9 br=""> {
x++;
cout<} 9>
getch();
}
3. DO...WHILE..
#include
#include
void main()
{ int x;
x=0;
do
{
x++;
cout<}while(x<9 br=""> getch();
}9> - 2468
1. FOR
#include
#include
void main()
{ int x;
for (x=2; x<10 br="" x=""> cout<getch(); 10>
}
2.WHILE
#include
#include
void main()
{ int x;
x=0;
while(x<=6)
{x+=2;
cout<}
getch();
}
atau
#include
#include
void main()
{ int x;
x=0;
while(x<8 br=""> {x+=2;
cout<} 8>
getch();
}
3. DO....WHILE
#include
#include
void main()
{ int x;
x=0;
do
{
x+=2;
cout<}while(x<=6);
getch();
} - 1357
1. FOR
#include
#include
void main()
{ int x;
for (x=1; x<10 br="" x=""> cout<getch(); 10>
}
2. WHILE
#include
#include
void main()
{ int x;
x=-1;
while(x<9 br=""> {x+=2;
cout<} 9>
getch();
}
3. DO...WHILE...
#include
#include
void main()
{ int x;
x=-1;
do
{
x+=2;
cout<}while(x<9 br=""> getch();
}9>
Sumber : Klik disini
0 komentar:
Posting Komentar