[ create a new paste ] login | about

Link: http://codepad.org/XNqPnY8v    [ raw code | output | fork ]

C++, pasted on Dec 17:
#include <iostream>


void fill_mat(int* arr, int n) {
	int k = 0;
	for(int i = 0; i < n; i++) {
	   if(i < (n/2+n%2))
	      arr[i*n+i] = arr[(n-1-i)*n+i] = ++k;
	   else
	      arr[i*n+i] = arr[(n-1-i)*n+i] = --k;
	}
}


int main(void) {
   const int N = 17;
   int mat[N][N] = {{0}};
   fill_mat((int*)mat, N);

   for(int r = 0; r < N; r++) {
      for(int c = 0; c < N; c++)
		  std::cout << mat[r][c] << "  ";
	  std::cout.put('\n');
   }
   return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  1  
0  2  0  0  0  0  0  0  0  0  0  0  0  0  0  2  0  
0  0  3  0  0  0  0  0  0  0  0  0  0  0  3  0  0  
0  0  0  4  0  0  0  0  0  0  0  0  0  4  0  0  0  
0  0  0  0  5  0  0  0  0  0  0  0  5  0  0  0  0  
0  0  0  0  0  6  0  0  0  0  0  6  0  0  0  0  0  
0  0  0  0  0  0  7  0  0  0  7  0  0  0  0  0  0  
0  0  0  0  0  0  0  8  0  8  0  0  0  0  0  0  0  
0  0  0  0  0  0  0  0  9  0  0  0  0  0  0  0  0  
0  0  0  0  0  0  0  8  0  8  0  0  0  0  0  0  0  
0  0  0  0  0  0  7  0  0  0  7  0  0  0  0  0  0  
0  0  0  0  0  6  0  0  0  0  0  6  0  0  0  0  0  
0  0  0  0  5  0  0  0  0  0  0  0  5  0  0  0  0  
0  0  0  4  0  0  0  0  0  0  0  0  0  4  0  0  0  
0  0  3  0  0  0  0  0  0  0  0  0  0  0  3  0  0  
0  2  0  0  0  0  0  0  0  0  0  0  0  0  0  2  0  
1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  1  


Create a new paste based on this one


Comments: