-
Notifications
You must be signed in to change notification settings - Fork 4
/
MatrixTranspose
54 lines (48 loc) · 892 Bytes
/
MatrixTranspose
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.*;
class MatrixTranspose
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int m,n,i,j;
System.out.println("Enter the number of rows:");
m=sc.nextInt();
System.out.println("Enter the number of columns:");
n=sc.nextInt();
int a[][]=new int[m][n],t[][]=new int[n][m];
System.out.println("Enter the matrix:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=sc.nextInt();
}
}
System.out.println("The matrix is:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
t[i][j]=a[j][i];
}
}
System.out.println("The transpose matrix is:");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
System.out.print(t[i][j]+" ");
}
System.out.println();
}
sc.close();
}
}