C++ "Looping Bersarang Wajik"
#include <iostream>using namespace std;int main(){int tinggi, baris;cout<<"Program Segitiga Wajik"<<endl;cout<<"----------------------"<<endl<<endl;cout<<"Masukkan Tinggi Wajik : "; cin>>tinggi;cout<<endl<<endl;
for (baris = 1; baris <= tinggi; baris++){
for (int i = 1; i <= tinggi - baris; i++){ cout<<" "; }for (int i = 1; i <= baris * 2 - 1; i++){ cout<<"*"; }cout<<endl;
}
for (baris = tinggi-1; baris >0; baris--){
for (int i = 1; i <= tinggi - baris; i++){ cout<<" "; }for (int i = 1; i <= baris * 2 - 1; i++){ cout<<"*"; }cout<<endl;
}
cout<<endl<<endl;
for (baris = tinggi; baris >0; baris--){
for (int i = 1; i <= tinggi - baris; i++){ cout<<" "; }for (int i = 1; i <= baris * 2 - 1; i++){ cout<<"*"; }cout<<endl;
}
for (baris = 2; baris <= tinggi; baris++){
for (int i = 1; i <= tinggi - baris; i++){ cout<<" "; }for (int i = 1; i <= baris * 2 - 1; i++){ cout<<"*"; }cout<<endl;
}
cout<<endl<<endl;
return 0;}
Hasilnya seperti ini: