//Multiplication of Two Matrix A anb B
import java.io.*;
class Matrix
{
public static void main(String dd[])
{
int A[][]=new int[3][3];
int B[][]=new int[3][3];
int C[][]=new int[3][3];
try
{
DataInputStream dis=new DataInputStream(System.in);
System.out.println("Enter Elements in Matrix A...");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
A[i][j]=Integer.parseInt(dis.readLine());
}
}
System.out.println("Enter Elements in Matrix B...");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
B[i][j]=Integer.parseInt(dis.readLine());
}
}
}
catch(Exception e){}
System.out.println("Multiplication of Matrix A and B is...");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
C[i][j]=0;
for(int k=0;k<3;k++)
{
C[i][j]=A[i][k]*B[k][j]+C[i][j];
}
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(" "+C[i][j]);
}
System.out.println("");
}
}
}
No comments:
Post a Comment