forked from Amigo2k20/java_programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplay Transpose Matrix
More file actions
62 lines (45 loc) · 1.3 KB
/
Display Transpose Matrix
File metadata and controls
62 lines (45 loc) · 1.3 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.util.Scanner;
class TRANSMatrix
{
public static void main(String args[])
{
int row, col,i,j,temp,n;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of rows");
row = in.nextInt();
System.out.println("Enter the number columns");
col = in.nextInt();
if(row >col)
n=row;
else
n= col;
int mat1[][] = new int[n][n];
System.out.println("Enter the elements of matrix");
for ( i= 0 ; i < row ; i++ )
{
for ( j= 0 ; j < col ;j++ )
mat1[i][j] = in.nextInt();
}
System.out.println("\n\nOriginal matrix:-");
for ( i= 0 ; i < row ; i++ )
{
for ( j= 0 ; j <col;j++ )
System.out.print(mat1[i][j]+" ");
System.out.println();
}
for ( i= 0 ; i < n; i++ )
for ( j= i+1 ; j < n;j++ )
{
temp=mat1[i][j] ;
mat1[i][j] =mat1[j][i] ;
mat1[j][i] =temp;
}
System.out.println("Transpose of matrix:-");
for ( i= 0 ; i < col ; i++ )
{
for ( j= 0 ; j < row;j++ )
System.out.print(mat1[i][j]+" ");
System.out.println();
}
}
}