#include #include #include int checkerror (int n, int z); void transmatrix (int *a, int *c, int n, int z); void snake (int *c, int n, int z); void swap (int *a, int *b); void sortwithbubble (int *num, int size); void freememorymatrix (void *a); int matrix (int n, int z, int *a); int *memoryformatrix (int n, int z); int printmatrix (int n, int z, int *a); int memoryallocationverification (int *a); int main () { int *a = NULL; int *c = NULL; int n, z; printf ("Enter the number of rows and columns\n"); scanf_s ("%d %d", &n, &z); int checkerror (int n, int z); a = memoryformatrix (n, z); c = memoryformatrix (n, z); memoryallocationverification (a); memoryallocationverification (c); matrix (n, z, a); printmatrix (n, z, a); printf ("\n"); sortwithbubble (a, n * z); printmatrix (n, z, a); printf ("\n"); transmatrix (a, c, n, z); snake (c, n, z); printmatrix (n, z, c); freememorymatrix (a); freememorymatrix (c); _getch (); return 0; } int * memoryformatrix (int n, int z) { return (int *) malloc (n * z * sizeof (int)); } int matrix (int n, int z, int *a) { int i, j = 0; for (i = 0; i < n; i++) { for (j = 0; j < z; j++) { printf ("a[%d][%d]=", i, j); scanf_s ("%d", (a + i * z + j)); } } return 0; } int printmatrix (int n, int z, int *a) { int i, j = 0; for (i = 0; i < n; i++) { for (j = 0; j < z; j++) { printf ("%3d", *(a + i * z + j)); } printf ("\n"); } return 0; } int memoryallocationverification (int *a) { if (a == NULL) { printf ("Error with memory allocation"); } return 0; } int checkerror (int n, int z) { if (n <= 0 || z <= 0) { printf ("n and z must be positive"); } return 0; } void transmatrix (int *a, int *c, int n, int z) { for (int i = 0; i < n; i++) { for (int j = 0; j < z; j++) { *(c + i * z + j) = *(a + j * n + i); } } } void snake (int *c, int n, int z) { float k = n / 2; for (int i = 0; i < k; i++) { for (int j = 0; j < z; j++) { if (j % 2 == 1) { swap ((c + i * z + j), (c + (n - 1 - i) * z + j)); } } } } void swap (int *a, int *b) { int temp; temp = *a; *a = *b; *b = temp; } void sortwithbubble (int *num, int size) { for (int i = 0; i < size - 1; i++) { for (int j = (size - 1); j > i; j--) { if (*(num + j - 1) > *(num + j)) { swap ((num + j - 1), (num + j)); } } } } void freememorymatrix (void *a) { free (a); }