Kamis, 26 Juni 2014

Contoh Program Barisan Bintang Jam Pasir C++



 Source code:
#include<iostream.h>

#include<conio>

#include<math.h>

#include<stdio.h>

main()

{

int a,b,c,d,e;

cout << "Masukkan Jumlah Baris: ";

cin>> a;

cout<<endl;

cout <<" ";

b=floor((a/2));

d=floor((a/2)-1);

e=floor((a/2)+1);

c=b+2;

for(int i=1;i<=a-2;i++){cout<<"%";}cout<<endl;

for(int j=1;j<=e-1;j++ )

{

for(int k=1;k<=a;k++)

{

if (k==1) {cout <<"%";}

else if (k==a){cout <<"%";}

else if (k==b){cout <<"%";}

else if (k==c){cout <<"%";}

else cout<<" ";

}

cout<<endl;

b=b-1;

c++;

}

int f=2;

int g=a-1;

for(int j=1;j<=d;j++ )

{

for(int k=1;k<=a;k++)

{

if (k==1) {cout <<"%";}

else if (k==a){cout <<"%";}

else if (k==f){cout <<"%";}

else if (k==g){cout <<"%";}

else cout<<" ";

}

cout<<endl;

f++;

g--;

}

cout <<" ";for(int i=1;i<=a-2;i++){cout<<"%";}cout<<endl;

getch () ;

} 

Tidak ada komentar:

Posting Komentar