Advertisement
xathrya

Pola 9

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