-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
253ed77
commit e2b6e45
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <iostream> | ||
using namespace std; | ||
int main () { | ||
//kita deklarasi beberapa variabel disini | ||
int tinggi,kolom,baris,itung; | ||
//kita output tulisan masukkan tinggi | ||
cout<<"masukkan tinggi"; | ||
//masukkan inputan ke variabel | ||
cin>>tinggi; | ||
//untuk membuat bintangnya 2 kali lipat namun -1 agar mempunyai puncak | ||
itung=(tinggi*2)-1; | ||
//loop untuk buat tinggi nya | ||
for (baris=1;baris<=tinggi;baris++){ | ||
//kolom spasi diawali dengan loop baris namun +1 agar spasinya berakhir di 0, bukan 1 | ||
for (kolom=baris+1;kolom<=tinggi;kolom++){ | ||
cout<< " "; | ||
} | ||
//kolom bintang, loop awal dari 1; hanya saja ujungnya yaitu sepanjang loop si baris dikali 2 dikurang 1; biar ada puncak segitiganya | ||
for(kolom=1;kolom<=(2*baris)-1;kolom++){ | ||
cout<< "*"; | ||
} | ||
//garis baru setelah loop si baris selese | ||
cout<<endl; | ||
} | ||
//loop untuk tinggi | ||
for(baris=0;baris<=tinggi;baris++){ | ||
//loop biasa untuk membuat banyaknya kolom=baris | ||
for (kolom=1;kolom<=baris;kolom++){ | ||
cout<<" "; | ||
} | ||
//loop bintang, ujungnya sama, hanya dia ngarah ke Tinggi, jadi 2xtinggi-1 | ||
for (kolom=1;kolom<=itung;kolom++){ | ||
cout<<"*"; | ||
} | ||
//tiap loop mau selese, si tinggi harus berkurang 2 agar ujung kanan dari si kolom bintang selaras ama ujung kiri | ||
itung-=2; | ||
//garis baru setelah tiap baris selese | ||
cout<<endl;; | ||
} | ||
} |