fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4.  
  5.  
  6. int main()
  7. {
  8.  
  9. printf("Enter size matrix: ");
  10. int n, cnt=0, temp, next_temp, next_i=0, next_j=0, sign_i=1, sign_j=0;
  11. int cycle=0;
  12. scanf("%d", &n);
  13.  
  14. int** matrix = (int**) malloc(n*sizeof(int));
  15. for (int i=0; i<n; i++)
  16. {
  17. matrix[i] = (int*)malloc(n*sizeof(int));
  18. for (int j=0; j<n; j++)
  19. matrix[i][j] = ++cnt;
  20. }
  21. printf("\nMatrix before overturn:");
  22. for (int i=0; i<n; i++)
  23. {
  24. printf("\n");
  25. for (int j=0; j<n; j++)
  26. printf(" %3i",matrix[i][j]);
  27. }
  28.  
  29. // сдвигаем
  30. for (cycle=0; cycle<n/2; cycle++)
  31. {
  32. next_i=cycle; next_j=cycle;
  33. next_temp=matrix[next_i][next_j];
  34. for (int i=0; i<4*(n-1-2*cycle); i++)
  35. {
  36. temp=next_temp;
  37. next_i-=sign_i; next_j-=sign_j;
  38. if(next_i<cycle) { next_i=cycle; sign_i=0; sign_j=-1; ++next_j; /*printf("1 ");*/}
  39. if(next_j>=n-cycle) { next_j=n-1-cycle; sign_i=-1; sign_j=0; ++next_i;/*printf("2 ");*/}
  40. if(next_i>=n-cycle) { next_i=n-1-cycle; sign_i=0; sign_j=1; --next_j; /*printf("3 ");*/}
  41. if(next_j<cycle) { next_j=cycle; sign_i=1; sign_j=0; --next_i; /*printf("4 ");*/}
  42. next_temp=matrix[next_i][next_j];
  43. matrix[next_i][next_j]=temp;
  44. //printf("(%i,%i): %i\n",next_i,next_j, matrix[next_i][next_j]);
  45. }
  46. }
  47.  
  48. printf("\nMatrix after overturn:");
  49. for (int i=0; i<n; i++)
  50. {
  51. printf("\n");
  52. for (int j=0; j<n; j++)
  53. printf(" %3i",matrix[i][j]);
  54. }
  55.  
  56. getch();
  57. return 0;
  58. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:19: fatal error: conio.h: No such file or directory
 #include <conio.h>
                   ^
compilation terminated.
stdout
Standard output is empty