import java.util.Scanner;
public class Transpose_matrix {
public static void main(String args[])
{
int m, n, c,d;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of rows and columns of matrix");
m = in.nextInt();
n = in.nextInt();
int first[][] = new int[m][n];
System.out.println("Enter the elements of matrix");
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
{
System.out.print(c+""+d+" Element : ");
first[c][d] = in.nextInt();
}
int transpose[][] = new int[n][m];
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < n ; d++ )
transpose[d][c] = first[c][d];
}
System.out.println("Transpose of entered matrix:-");
for ( c = 0 ; c < n ; c++ )
{
for ( d = 0 ; d < m ; d++ )
System.out.print(transpose[c][d]+"\t");
System.out.print("\n");
}
}
}
OUTPUT ::
Enter the number of rows and columns of matrix
3
2
Enter the elements of matrix
00 Element : 1
01 Element : 2
10 Element : 3
11 Element : 4
20 Element : 5
21 Element : 6
Transpose of entered matrix:-
1 3 5
2 4 6
SOURCE CODE ::
OUTPUT ::
need an explanation for this answer? contact us directly to get an explanation for this answer