fork download
  1. #include <stdio.h>
  2.  
  3. /* The function in 97 bytes. */
  4. int f(int n,int a[n][n],int*b){for(int i=0;i<n;i++)for(int j=0,k=n;j<n;j++)*b++=a[i][i%2?j:--k];}
  5.  
  6. int main(void) {
  7. /* N != 0. */
  8. #define N 4
  9.  
  10. /* Declaration of the input array. */
  11. #if N == 4
  12. int input[N][N] = {{4, 3, 2, 1}, {5, 6, 7, 8}, {12, 11, 10, 9}, {13, 14, 15, 16}};
  13. #elif N == 3
  14. int input[N][N] = {{3, 2, 1}, {4, 5, 6}, {9, 8, 7}};
  15. #elif N == 2
  16. int input[N][N] = {{2, 1}, {3, 4}};
  17. #elif N == 1
  18. int input[N][N] = {{1}};
  19. #endif
  20.  
  21. /* Declaration of the output array. */
  22. int output[N * N];
  23.  
  24. /* Process. */
  25. f(N, input, output);
  26.  
  27. /* Check the result. */
  28. for (size_t i = 0; i < N*N; i++)
  29. printf("%d ", output[i]);
  30. }
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16