-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranspose.java
More file actions
47 lines (39 loc) · 859 Bytes
/
transpose.java
File metadata and controls
47 lines (39 loc) · 859 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
import java.util.Scanner;
class transpose
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of rows and columns of the matrix\n");
int r = sc.nextInt();
int c = sc.nextInt();
int arr[][] = new int[r][c];
int t[][] = new int[c][r];
int i,j;
System.out.println("Enter the elements\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
arr[i][j] = sc.nextInt();
}
System.out.println(" the matrix\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
System.out.print(arr[i][j]+" ");
System.out.println();
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
t[j][i]=arr[i][j];
}
System.out.println(" transpose of the matrix");
for(i=0;i<c;i++)
{
for(j=0;j<r;j++)
System.out.print(t[i][j]+" ");
System.out.println();
}
}
}