/* Two-dimensional array solution, dynamic space allocation */ # Include <stdio. h> # Include <stdlib. h> # Include <memory. h> Int main (void) { Int n; // number of rows Int m; // Number of Columns Scanf ("% d", & n ); Scanf ("% d", & m ); // Allocate space for the input two-dimensional data Int ** input = (int **) malloc (sizeof (int *) * n); // allocate space for rows For (int I = 0; I <n; I ++) // allocate space to the column { Input [I] = (int *) malloc (sizeof (int) * m ); Memset (input [I], 0, sizeof (int) * m ); } // Allocate space to the output two-dimensional array Int ** output = (int **) malloc (sizeof (int *) * m); // allocate space for rows For (int I = 0; I <m; I ++) // allocate space to the column { Output [I] = (int *) malloc (sizeof (int) * n ); Memset (output [I], 0, sizeof (int) * n ); } For (int I = 0; I <n; I ++) { For (int j = 0; j <m; j ++) { Scanf ("% d", & input [I] [j]); Output [m-1-j] [I] = input [I] [j]; } } For (int I = 0; I <m; I ++) { For (int j = 0; j <n; j ++) { If (j = N-1) { Printf ("% d \ n", output [I] [j]); } Else { Printf ("% d", output [I] [j]); } } } // Reclaim the memory allocated to the input Array For (int I = 0; I <n; I ++) { Free (input [I]); } Free (input ); // Reclaim the memory allocated to the output Array For (int I = 0; I <m; I ++) { Free (output [I]); } Free (output ); Return 0; } |