Program C++ Membuat Bentuk-Bentuk Segitiga dengan Perulangan


Script

#include <iostream.h>
#include <conio.h>
void main()
{
 int i,j,k,n;
cout<<“=======================\n”;
cout<<“PROGRAM BENTUK SEGITIGA\n”;
cout<<“=======================\n\n”;
cout<<“Masukkan Tinggi Segitiga : “;
cin>>n;
cout<<“\n”;
cout<<“Segitiga A\n\n”;
for (i=n;i>0;i–)
{
for(j=i;j>0;j–)
{
cout<<” “;
}
for(k=0;k<=n-i;k++)
{
cout<<“*”;
}
for(k=0;k<n-i;k++)
{
cout<<“*”;
}
cout<<“\n”;
}
cout<<“\n\nSegitiga B\n\n”;
for (i=1;i<=n;i++)
{
for (j=1;j<=i;j++)
{
cout<<” “;
}
for (k=0;k>=(i-n);k–)
{
cout<<“*”;
}
for(k=0;k<(n-i);k++)
{
cout<<“*”;
}
cout<<“\n”;
}
cout<<“\n\nSegitiga C\n\n”;
for(j=1;j<=n;j++)
{
for(i=1;i<=j;i++)
{
cout<<“*”;
}
cout<<“\n”;
}
for(j=1;j<=n;j++)
{
for(i=1;i<=n-j;i++)
{
cout<<“*”;
}
cout<<“\n”;;
}
getch();
getch();
}

Hasil

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s