Program to Transpose a 2D Array.
#include <stdio.h>
// Function to transpose a 2D array
void transposeArray(int arr[][3], int rows, int cols) {
int transposed[cols][rows];// Performing the transpose operation
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
transposed[j][i] = arr[i][j];
}
}// Printing the transposed array
printf(“Transposed array:n”);
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
printf(“%d “, transposed[i][j]);
}
printf(“n”);
}
}int main() {
int rows, cols;// Taking input for the number of rows and columns
printf(“Enter the number of rows: “);
scanf(“%d”, &rows);printf(“Enter the number of columns: “);
scanf(“%d”, &cols);int array[rows][cols];
// Taking input for array elements
printf(“Enter %d x %d elements:n”, rows, cols);
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
scanf(“%d”, &array[i][j]);
}
}// Calling the function to transpose the array and printing the result
transposeArray(array, rows, cols);return 0;
}