Sunday, July 22, 2018

Program C++ Membuat Bintang Berbentuk Belah Ketupat | Algoritma Pemrograman

ALGORITMA
Program Bintang
Deklarasi
   n,i,j,s:integer
Algoritma
   read (n)
   for (int i=1 to i<=n) do
   { for (j=0 to j<(n-i)) do
            write (' ')
      for (j=1 to j<=i) do
            write ('*')
      for (s=1 to s<i) do
            write ('*')}
   endfor
   for (int i=n-1 downto i>=1) do
    { for (j=0 to j<(n-i)) do
            write (' ')
       for (j=1 to j<=i) do
             write ('*')
       for (s=1 to s<i)
             write ('*') }
   endfor

CODING
#include <iostream>
using namespace std;
int main() {
    int n,i,j,s;
    cout<<"Masukan Jumlah Baris Bintang=";cin>>n;
    for (int i=1; i<=n;i++)
    {   for (j=0;j<(n-i);j++)
        cout<<" ";
        for (j=1;j<=i;j++)
        cout<<"*";
        for (s=1;s<i;s++)
        cout<<"*";
        cout<<endl;
     }
         for (int i=n-1;i>=1;i--)
    {   for (j=0;j<(n-i);j++)
        cout<<" ";
        for (j=1;j<=i;j++)
        cout<<"*";
        for (s=1;s<i;s++)
        cout<<"*";
        cout<<endl;
    }
    system("PAUSE");
}



KELUARAN





No comments:

Post a Comment