Transpose of a Matrix – ARRAY in C


First, what is an ARRAY?

Actually, Array is a group of elements having similar data type (either int, char, float, etc.) with continuous memory allocation.

Arrays are of 2 types –

1.)    Single-Dimensional (having only one dimension either row or either column)

–> Declaration – <data type><variable name>[no. of elements].

–> Example – int arr[10], means an integer type array arr containing 10 elements.

2.)    Multi-Dimensional (having more than one dimensions either more than one rows or either more than one columns).

–> Declaration – <data type><variable name>[no. of rows][no. of columns].

–> Example – int arr[10][10], means an integer type array arr containing 10 rows & 10 columns.


Now here we are going to transpose the array, means

If the inputted array is –



the output should be –


Means, rows & columns should be interchanged.

For transforming matrix, first we need to take the input of rows & columns in the variable r & c. Also we have to initialize the array variable with any of the value as here we have arr[100][100] means 100 rows & 100 columns. Now what we are doing here is, changing the rows with the columns. Here we are running a for loop with variable ifor rows & variable j for columns. At last we are just changing the variables i à j and j à i.

As in the program, arr[i][j] is changed to arr[j][i].


Author Description


Our mission is to bring the affordable Technology education to people everywhere, in order to help them achieve their dreams and change the world. - Follow @program_guide

No comments yet.

Join the Conversation