Subscribe:

Ads 468x60px

Pages

Minggu, 03 Juni 2012

Piramid Kanan program c++


Pyramid kanan

Program pyramid kanan, ini adalah contoh program pyramid kanan dalam program c++ sebagai berikut


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

void main()
{
                clrscr();
                int a, b, c, d, e, f, g;
                cout<<"Masukkan angka :";cin>>a;
                cout<<"\n";
                for(b = 1;b <= a;b++)
                {
                                for(c = a;c > b;c--)
                                {
                                                cout<<"  ";
                                }

                                for(d = 1;d <= b;d++)
                                {
                                                cout<<"* ";
                                }
                                cout<<endl;

                                if(b == a)
                                {
                                                for(e = 1;e <= a;e++)
                                                {
                                                                for(f = 1;f <= e;f++)
                                                                {
                                                                                cout<<"  ";
                                                                }

                                                                for(g = a;g > e;g--)
                                                                {
                                                                                cout<<"* ";
                                                                }
                                                                cout<<endl;
                                                }
                                }
                }

                getch();

  }


Contoh outputnya



silahkan mencoba, terima kasih

Tidak ada komentar:

Posting Komentar