Q> Add two matrices.
import [Link].* ;
class MatAdd
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]) ;
int R, C, i, j ;
[Link]("Enter the Order of the Matrices [R, C] : ") ;
R = [Link]() ;
C = [Link]() ;
if(R<=0 || C<=0)
[Link]("Invalid Input.") ;
else
{
int A[][] = new int[R][C] ;
int B[][] = new int[R][C] ;
[Link]("Enter the 1st Matrix : -") ;
for(i=0 ; i<R ; i++)
{
for(j=0 ; j<C ; j++)
{
A[i][j] = [Link]() ;
}
}
[Link]("Enter the 2 nd Matrix : -") ;
for(i=0 ; i<R ; i++)
{
for(j=0 ; j<C ; j++)
{
B[i][j] = [Link]() ;
}
}
[Link]("The Result is : -") ;
for(i=0 ; i<R ; i++)
{
for(j=0 ; j<C ; j++)
{
[Link]( (A[i][j]+B[i][j]) + " \t" ) ;
}
[Link]() ;
}
}}
1
Q> Generate the Transpose of a matri x.
import [Link].* ;
class Transpose
{
public static void main(String args[])
{
Scanner sc = new Scanner([Link]) ;
int R, C, i, j ;
[Link]("Enter the Order of the Matrix [R C] : ") ;
R = [Link]() ;
C = [Link]() ;
if(R<=0 || C<=0)
[Link]("Invalid Input.") ;
else
{
int A[][] = new int[R][C] ;
[Link]("Enter the Matrix : -") ;
for(i=0 ; i<R ; i++)
{
for(j=0 ; j<C ; j++)
{
A[i][j] = [Link]() ;
}
}
[Link]("The Transpose is : -") ;
for(j=0 ; j<C ; j++)
{
for(i=0 ; i<R ; i++)
{
[Link]( A[i][j] + " \t" ) ;
}
[Link]() ;
}
}}