Minggu, 26 Mei 2013

Membuat Bentuk Segitiga Sama Sisi dan Belah Ketupat dengan C++

#include <iostream.h>
#include <conio.h>

void main()
{
clrscr();
cout<<"NAMA    : HAPSARI RATNA MANDALAWATI\n";
cout<<"NIM    : 201251108\n";
cout<<"\n==============================================\n";
cout<<"=> Membuat Bentuk Segitiga Sama Sisi <=\n";
cout<<"\n==============================================\n";
int x,i,j,k;
cout<<"=> Masukkan tinggi : ";
cin>>x;
for(i=1;i<=x;i++)
{
for(j=x;j>=i;j--)
{
cout<<" ";
}
for(k=1;k<=i+(i-1);k++)
{
cout<<"*";
}
cout<<endl;
}
cout<<"\n==============================================\n";
cout<<"=> Membuat Bentuk Belah Ketupat <=\n\n";
cout<<"\n==============================================\n";
int a,b,c,n;
do
{
cout <<"Masukkan Tinggi Belah Ketupat (Harus Bilangan Ganjil) : ";
cin>>n;
}
while (n%2==0);
for(int a=0; a<=n; a+=2)
{
for(int b=0; b<n-a; b+=2)
{
cout<<" ";
}
for (c=0;c<=a; c++)
{
cout<<"*";
}
cout<<endl;
}
n=n-2;
for (a=0; a<n;a+=2)
{
for (b=0; b<=a+2; b+=2)
{
cout<<" ";
}
for (c=1; c<=n-a; c++)
{
cout<<"*";
}
cout<<endl;
}
cout<<"\n==================SELESAI=====================\n";
getch();
}

Hasilnya =>

Tidak ada komentar: