Advertisement
xathrya

Pola 3

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