-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranspose of Matrix.java
More file actions
42 lines (41 loc) · 1.06 KB
/
Transpose of Matrix.java
File metadata and controls
42 lines (41 loc) · 1.06 KB
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
// to find transpose of a matrix
import java.util.*;
import java.io.*;
class Transpose
{
public static void main(String a[])
{
int i,j;
Scanner sc= new Scanner(System.in);
System.out.println("Enter the number of rows and columns in the matrix");
int row = sc.nextInt();
int col = sc.nextInt();
int[][] arr = new int [row][col];
System.out.println("Enter the matrix elements");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
arr[i][j]=sc.nextInt();
}
}
System.out.println("The matrix is");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println(" ");
}
System.out.println("The transpose of the matrix is");
for(i=0;i<col;i++)
{
for(j=0;j<row;j++)
{
System.out.print(arr[j][i]+" ");
}
System.out.println(" ");
}
}
}