Subscribe:

Ads 468x60px

Pages

Minggu, 03 Juni 2012

Pyramid kanan yang tengah nya kosong program c++


Pyramid kanan yang tengah nya kosong

Program pyramid kanan yang tengah nya kosong 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++)
                                {
                                                if(d == 1 || d == b)
                                                                cout<<"* ";
                                                else
                                                                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--)
                                                                {
                                                                                if(g == a || g == e + 1)
                                                                                                cout<<"* ";
                                                                                else
                                                                                                cout<<"  ";
                                                                }
                                                                cout<<endl;
                                                }
                                }
                }

                getch();
}

Contoh outputnya


silahkan mencoba dan terima kasih

Tidak ada komentar:

Posting Komentar