// Program
import
java.util.Scanner;
public class
Matrix_Multiplication
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[10][10];
int b[][]=new int[10][10];
int c[][]=new int[10][10];
int sum=0;
System.out.println("Enter elements
for 1st Matrix");
for(int i=1;i<=2;i++)
{
for(int j=1;j<=2;j++)
{
a[i][j]=sc.nextInt();
}
}
System.out.println("First Matrix
is");
for(int i=1;i<=2;i++)
{
for(int j=1;j<=2;j++)
{
System.out.print("\t"+a[i][j]);
}
System.out.print("\n");
}
System.out.println("Enter elements
for 2nd Matrix");
for(int i=1;i<=2;i++)
{
for(int j=1;j<=2;j++)
{
b[i][j]=sc.nextInt();
}
}
System.out.println("Second Matrix
is");
for(int i=1;i<=2;i++)
{
for(int j=1;j<=2;j++)
{
System.out.print("\t"+b[i][j]);
}
System.out.print("\n");
}
for(int i=1;i<=2;i++)
{
for(int j=1;j<=2;j++)
{
for(int k=1;k<=2;k++)
{
sum=sum+a[i][k]*b[k][j];
}
c[i][j]=sum;
sum=0;
}
}
System.out.println("After
Multiplication the matrix is");
for(int i=1;i<=2;i++)
{
for(int j=1;j<=2;j++)
{
System.out.print("\t"+c[i][j]);
}
System.out.print("\n");
}
}
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.