Diposting oleh :
Unknown | Dirilis :
18.31 | Series :
PROGRAM PERULANGAN FOR, WHILE, DAN DO WHILE
FOR
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
void main(){
for(int a=5;a>=1;a--){
for(int b=1;b<=a;b++){
cout<<" *";
}
cout<<endl;
}
for(int a=2;a<=5;a++){
for(int b=1;b<=a;b++){
cout<<" *";
}
cout<<endl;
}
getch();
}
WHILE
#include
<conio.h>
#include
<stdio.h>
#include<iostream.h>
void main()
{
int a=1;
while (a<=5){
int b=5;
while (b>=a){
cout<<"*";
b--;
}
cout<<endl;
a++;
}
int b=1;
while (b<=5){
int a=1;
while (a<=b){
cout<<"*";
a++;
}
cout<<endl;
b++;
}
getch();
}
DO WHILE
#include
<conio.h>
#include
<stdio.h>
#include
<iostream.h>
void main()
{
int a,b;
a=1;
do {
b=5;
do {
cout<<"*";
b--;
}
while(b>=a);
cout<<endl;
a++;
}
while(a<=5);
b=1;
do {
a=1;
do {
cout<<"*";
a++;
}
while(a<=b);
cout<<endl;
b++;
}
while(a<=5);
getch();
}