Get paid to share your links!

Program Belah Ketupat dengan Angka C++

Friday, February 22, 2013

compiler : Borland C++
Algoritma :
  1.          Start
  2.          Masukkan angka n(1-9)
  3.          Baris tengah sesuai dengan angka yang dimasukkan, urut dari yang terkecil hingga angka ke-n
  4.          Kolom tengah sesuai dengan angka yang dimasukkan, urut dari yang terkecil hingga angka ke-n
  5.          Membentuk 2 segitiga n dan kemudian menggabungkannya dengan membalik segitiga yang kedua
  6.          Menampilkan belah ketupat dengan angka
  7.          End
Source code

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
void main()
{
int i, j, k;
cout<<"Masukkan Angka (1-9): ";
cin>>k;
clrscr();
for(i=1;i<=k;i++)
{
for(j=1;j<=k-i;j++)
{
cout<<" ";
}
   for(j=1;j<=i;j++)
   {
   cout<<j;
   }
for(j=i-1;j>=1;j--)
{
cout<<j;
}
cout<<endl;
}
for(i=k;i>=1;i--)
{
for(j=1;j<=k-i;j++)
{
cout<<" ";
}
   for(j=1;j<=i;j++)
   {
   cout<<j;
   }
for(j=i-1;j>=1;j--)
{
cout<<j;
}
cout<<endl;
}

getch();
}
Share this article :

0 comments:

Speak up your mind

Tell us what you're thinking... !

Followers

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Blog - All Rights Reserved
Template Created by Creating Website Inspired by Sportapolis Shape5.com
Proudly powered by Blogger