Program c++ Membuat tanda plus (+)

Berikut adalah contoh program c++ membuat tanda Plus (+) :

#include <iostream.h>

#include <conio.h>

void main ()

{

clrscr();

int i, j, n;

cout <<“Masukkan jumlah perulangan : “; cin >> n;

if (n%2)

{

for (i=1; i<=n; i++)

{

for (j=1; j<=n; j++)

{

if ((i==(n-i)+1)||(j==(n-j)+1))

{

cout <<“*”;

}

else cout <<” “;

}

cout <<endl;

} getch();

}

else

{

for (i=1; i<=n; i++)

{

for (j=1; j<=n; j++)

{

if ((i==(n/2)+1||i==(n/2))||(j==(n/2)+1||j==(n/2)))

{

cout <<“*”;

} else cout <<” “;

} cout <<endl;

} getch();

}

}

^Rachmatika Irfani^

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s