For a better life with technology

Wednesday, October 25, 2017

Program C++ : Membuat Kotak Tengahnya Bolong

Cara membuat kotak yang tengahnya bolong dengan menggunakan bahasa pemograman C++.
Dengan kita bebas memasukkan input yang kita mau.




Coding :


#include <iostream.h>
#include <conio.h>

int main()

{
cout<<("input : ");
int n;
cin>>n;

if (n > 2){
//baris

for (int i=0; i < n; i++){
//kolom

for (int j=0; j < n; j++) {
//kondisi pembentuk kota

if ((i==0) || (i==n-1) || (j==0) || (j==n-1)) {
cout<<("*");
}
else
{
//kondisi bolong tengahnya
if (n%2==1){
{
cout<<(" ");
}
}
else {
cout<<(" ");
}
}
}//akhir kolom
cout<<"\n";
}//akhir baris
}
getch();
}
}
Share:

0 comments:

Post a Comment