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, 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, 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 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].