Type Here to Get Search Results !

Write a Java Program to determine the Multiplication of two matrices.

 import java.io.*; 

import java.util.*; 

class MatrixMul 

{ 

public static void main(String arg[]) 

{ 

int i=0,j=0,k=0; 

Scanner s=new Scanner(System.in); 

System.out.println("Enter order of matrix for A"); 

int m=s.nextInt(); 

int n=s.nextInt(); 

System.out.println("Enter order of matrix for B"); 

int p=s.nextInt(); 

int q=s.nextInt(); 

int a[][]=new int[10][10]; 

int b[][]=new int[10][10]; 

int c[][]=new int[10][10]; 

 if(n==p) 

{

System.out.println("Enter elements for matrix A"); for(i=0;i<m;i++) 

 for(j=0;j<n;j++) 

a[i][j]= s.nextInt();  

  

System.out.println("Enter elements for matrix B ");  for(i=0;i<m;i++) 

 for(j=0;j<n;j++) 

b[i][j]=s.nextInt(); 

  

 for(i=0;i<m;i++) 

 { 

 for(j=0;j<q;j++) 

 { 

for(k=0;k<p;k++) 

 c[i][j]=c[i][j]+a[i][k]*b[k][j]; 

 } 

 } 

System.out.print("Multiplication of resultant matrix is:");  for(i=0;i<m;i++) 

 { 

 for(j=0;j<q;j++) 

 { 

 System.out.print(" " +c[i][j]); 

 } 

 System.out.println("\n"); 

 } 

} 

} 

} 

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Featured post

M

M