1. Program menggunakan perulangan FOR
#include <iostream.h>
main (){
int x=10;
char huruf;
cout << "PROGRAM COBA PERULANGAN FOR" << endl;
huruf='a';
for (int z=1;z<=x;z++)
{
for(int y=z;y<=x;y++)
cout << " ";
for (int x=1;x<=z;x++)
cout <<huruf<<" ";
cout << endl;
huruf++;
z++;
}
for (int v=1;v<=x-1;v++){
for (int u=1;u<=v+3;u++)
cout << " ";
for (int q=v+1;q<=x-2;q++)
cout <<huruf<<" ";
cout << endl;
huruf++;
v++;
}
}
#OUTPUTNYA SBB;
2. Program Perulangan WHILE
#include <iostream.h>
main (){
int x=10;
char huruf;
huruf='a';
cout << "PROGRAM WHILE"<< endl;
int a=1;
int b=10;
while(a<=b){
int d=x;
while (d>=a){
cout << " ";
d--;
}
int e=1;
while (e<=a){
cout <<huruf<<" ";
e++;
}
huruf++;
cout <<endl;
a=a+2;
}
int g=1;
int h=x;
while(g<=h){
int i=1;
while(i<=g+3){
cout << " ";
i++;
}
int k=1;
int l=x-2;
while(k<=l-g){
cout<< huruf<<" ";
k++;
}
cout <<endl;
g=g+2;
huruf++;
}
}
#OUTPUTNYA
3.Porgram Menggunakan DO-WHILE
#include <iostream.h>
main (){
int x=10;
char huruf;
huruf='a';
cout << "PROGRAM DO-WHILE"<<endl;
int a=1;
int b=x;
do{
int c=1;
int d=x+1;
do{
cout <<" ";
c++;
}while(c<=d-a);
int e=1;
do{
cout <<huruf<<" ";
e++;
}while(e<=a);
cout <<endl;
a=a+2;
huruf++;
}while(a<=b);
int g=1;
int h=x-2;
do{
int i=1;
do{
cout <<" ";
i++;
}while(i<=g+3);
int k=1;
int l=8;
do{
cout <<huruf<<" ";
k++;
}while(k<=l-g);
cout <<endl;
g=g+2;
huruf++;
}while(g<=h);
}
#OUTPUTNYA
copas program di atas kemudian edit sesuai dengan soal tugas yang di berika
Tidak ada komentar:
Posting Komentar