Pyramid Shape dengan Perulangan
//program : piramid.cpp
#include<iostream>
#include<iomanip>
#include<conio.h>
using namespace std;
int main()
{
char letter;
int width;
int base;
int a;
int b = 1;
int counter = 0;
cout<<"Karakter yang anda masukan akan berubah menjadi piramid"<<endl;
cout<<"sejumlah banyaknya bilangan yang dimasukan."<<endl;
while(cin)
{
cout<<"\nMasukan simbol: "<<endl;
cin>>letter;
cout<<"masukan bilangan: "<<endl;
cin>>base;
width = (base/2) + 5 - counter;
a = 1;
while(width > 5)
{
width = (base/2) + 5 - counter;
cout<<setw(width)
;
while(b > 0)
{
cout<<letter;
b--;
}
cout<<endl;
b = (a * 2) - 1;
width--;
b = b + 2;
a++;
counter++;
}
b = 1;
counter = 0;
}
cout<<endl;
getch();
}
#include<iostream>
#include<iomanip>
#include<conio.h>
using namespace std;
int main()
{
char letter;
int width;
int base;
int a;
int b = 1;
int counter = 0;
cout<<"Karakter yang anda masukan akan berubah menjadi piramid"<<endl;
cout<<"sejumlah banyaknya bilangan yang dimasukan."<<endl;
while(cin)
{
cout<<"\nMasukan simbol: "<<endl;
cin>>letter;
cout<<"masukan bilangan: "<<endl;
cin>>base;
width = (base/2) + 5 - counter;
a = 1;
while(width > 5)
{
width = (base/2) + 5 - counter;
cout<<setw(width)
;
while(b > 0)
{
cout<<letter;
b--;
}
cout<<endl;
b = (a * 2) - 1;
width--;
b = b + 2;
a++;
counter++;
}
b = 1;
counter = 0;
}
cout<<endl;
getch();
}
Komentar
Posting Komentar