Advertisement
xathrya

Pola5

Nov 21st, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <cstdio>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int N, i, j;
  6.     char space_char = ' ';
  7.     int full, half, ibatas1, ibatas2;
  8.    
  9.     printf("Nilai N : ");
  10.     scanf("%d", &N);
  11.     full = N;
  12.     half = N/2;
  13.        
  14.     for (i=0; i<full; i++) {
  15.         ibatas1 = i%half;
  16.         ibatas2 = half-ibatas1-1;
  17.         if (ibatas1-ibatas2==1) {
  18.             if (space_char=='*') {
  19.                 space_char=' ';
  20.             } else {
  21.                 space_char='*';
  22.             }
  23.         }
  24.         for (j=0; j<half; j++){
  25.             if (j==ibatas1 || j==ibatas2) {
  26.                 printf("#");
  27.             } else if ( (j > ibatas1 && j < ibatas2) ||
  28.                         (j > ibatas2 && j < ibatas1))
  29.             {
  30.                 printf("%c", space_char);
  31.             } else {
  32.                 printf(" ");
  33.             }
  34.         }
  35.         printf("\n");
  36.     }
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement