import java.util.*;
class trans
{
public static void main(String arg[])
{
int a[][]=new int[4][4];
int i,j,temp;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the elements of array");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
temp=a[i][j];
a[i][j]=a[j][i];
a[j][i]=temp;
}
}
System.out.println("The TRANSPOSE OF MATRIX IS:");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
System.out.print(a[i][j]+"\t");
}
System.out.println();
}
}
}
OUTPUT:
Enter the elements of array
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
The TRANSPOSE OF MATRIX IS:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
class trans
{
public static void main(String arg[])
{
int a[][]=new int[4][4];
int i,j,temp;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the elements of array");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
a[i][j]=sc.nextInt();
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
temp=a[i][j];
a[i][j]=a[j][i];
a[j][i]=temp;
}
}
System.out.println("The TRANSPOSE OF MATRIX IS:");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
System.out.print(a[i][j]+"\t");
}
System.out.println();
}
}
}
OUTPUT:
Enter the elements of array
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
The TRANSPOSE OF MATRIX IS:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
No comments:
Post a Comment