+ 1

Convert row. In column in 2d array

C language

9th Jan 2023, 6:45 PM
Naman Pandey
Naman Pandey - avatar
1 Respuesta
0
This process is known as transpose. #include <stdio.h> #define M 3 #define N 4 int main(void) { int arr[M][N] = { {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12} }; int transposed[N][M]; for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) { transposed[j][i] = arr[i][j]; } } // print the transposed array for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { printf("%d ", transposed[i][j]); } printf("\n"); } return 0; }
9th Jan 2023, 7:21 PM
Aditya Dixit