Here is the Program to Find Transpose of a Matrix JAVA.
What Is Transpose Matrix?
Transpose of a Matrix is defined as “A Matrix which is formed by turning all the rows of a given matrix into columns and vice-versa.”
Checkout:- Program to sort non-boundary elements of matrix in Descending Order
Checkout:- Spiral Matrix or Clockwise Circular Matrix - Java
We
are uploading these types of program. However, if you need fully
compiled solution of any type of Java program then simply leave a
comment below, we will help you at the earliest. 😊😊
import java.util.*;
public class Transpose_of_Matrix
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of Rows");
int r=sc.nextInt();
System.out.println("Enter the number of Columns");
int c=sc.nextInt();
int arr[][]=new int[r][c];
int brr[][]=new int[c][r];
System.out.println("Enter the elements of Matrix");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
arr[i][j]=sc.nextInt();
}
}
System.out.println("Input Matrix is :");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println("");
}
for(int i=0;i<c;i++) //creating transpose
{
for(int j=0;j<r;j++)
{
brr[i][j]=arr[j][i];
}
}
System.out.println("Transpose of Input Matrix is :");
for(int i=0;i<c;i++)
{
for(int j=0;j<r;j++)
{
System.out.print(brr[i][j]+" ");
}
System.out.println("");
}
}
}
------------
OUTPUT:-
------------
Enter the number of Rows
4
Enter the number of Columns
4
Enter the elements of Matrix
1
5
6
9
8
7
4
5
2
3
6
5
4
1
5
3
Input Matrix is :
1 5 6 9
8 7 4 5
2 3 6 5
4 1 5 3
Transpose of Input Matrix is :
1 8 2 4
5 7 3 1
6 4 6 5
9 5 5 3
------------------------------
Checkout:- Sort Matrix in Ascending Order Java
0 Comments
Just write down your question to get the answer...