0% found this document useful (0 votes)
2 views

5.4 Matrix Multiplication

Uploaded by

mrnirajbro
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

5.4 Matrix Multiplication

Uploaded by

mrnirajbro
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

Scanner;

public class matrix {

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);

int a[][] = new int[3][3];


int b[][]=new int[3][3];
int c[][] = new int[3][3];
int i,j,k;

System.out.println("Enter the elements of the array:");


for ( i = 0; i < 3; i++) {
for(j=0;j<3;j++)
{

a[i][j] = sc.nextInt();
}}

System.out.println("Enter e elements of the array:");


for ( i = 0; i < 3; i++) {
for(j=0;j<3;j++)
{

b[i][j] = sc.nextInt();
}}

// matric addition
for ( i = 0; i < 3; i++) {
for(j=0;j<3;j++)
{ c[i][j]=0;
for(k=0;k<3;k++)
{
c[i][j] = c[i][j]+a[i][k]*b[k][j];
}}}
System.out.println("Addition of matrix:");
for ( i = 0; i < 3; i++) {
for(j=0;j<3;j++)
{
System.out.println(c[i][j]+"");
}
System.out.println();
}

You might also like