-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranspose.java
More file actions
50 lines (49 loc) · 965 Bytes
/
Copy pathtranspose.java
File metadata and controls
50 lines (49 loc) · 965 Bytes
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
import java.util.*;
class transpose
{
public static void main(String args[])
{
int a[][]=new int[50][50];
int t[][]=new int[50][50];
int i,j,row,col;
Scanner s1=new Scanner(System.in);
System.out.println("Enter the no.of rows in the matrix:");
row=s1.nextInt();
System.out.println("Enter the no.of columns in the matrix:");
col=s1.nextInt();
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
System.out.println("Enter the a["+i+"]["+j+"]th element:");
a[i][j]=s1.nextInt();
}
}
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
t[i][j]=a[j][i];
}
}
System.out.println("The matrix is:");
for(i=0;i<row;i++)
{
System.out.println("\n");
for(j=0;j<col;j++)
{
System.out.print(a[i][j]+"\t");
}
}
System.out.println("The transpose of the matrix is:");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
System.out.print(t[i][j]+"\t");
}
System.out.println("\n");
}
s1.close();
}
}