Advertisement
xathrya

Pola 3 _ All Cases

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