# Problem 37

### 3 comments on “Problem 37”

• rohan

#include
int i,j,k;
void print(int mat1[3][3],int mat2[3][3]);
void multi(int mat1[3][3],int mat2[3][3]);
int main()
{
int mat1[3][3],mat2[3][3],t[3][3];
printf(“elements for 1st and 2nd array\n”);
print(mat1,mat2);
multi(mat1,mat2);
return 0;
}
{
printf(“enter elements of 1st matrix\n”);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf("%d",&mat1[i][j]);
}
printf("enter elements of 2nd matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf("%d",&mat2[i][j]);
}
}
void print(int x[3][3],int y[3][3])
{

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf("%d \t",x[i][j]);
printf("\t");
for(j=0;j<3;j++)
printf("%d \t",y[i][j]);
printf("\n");
}
printf("\n");
}
void multi(int mat1[3][3],int mat2[3][3])
{
int temp;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(int k=0;k<3;k++)
temp=temp+((mat1[i][k])*(mat2[k][j]));
printf("%d\t",temp);
temp=0;
}
printf("\n");
}
}

• Oindry

import java.util.Scanner;
public class PREP_p_37 {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int row = sc.nextInt();
int col = sc.nextInt();
int a[][]= new int[row][col];
int b[][]= new int[row][col];
int c[][]= new int[row][col];
for(int i =0;i<row;i++)
{
for(int j =0;j<col;j++)
{
a[i][j] = sc.nextInt();
}
}
for(int i =0;i<row;i++)
{
for(int j =0;j<col;j++)
{
b[i][j] = sc.nextInt();
}
}
int i=0,j=0,k=0;
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
c[i][j]=0;
for(k=0;k<col;k++)
{
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
System.out.print(c[i][j]+" ");
}
System.out.println();
}
}
}
INPUT:-
3 3
1
1
1
2
2
2
3
3
3
1
1
1
2
2
2
3
3
3
OUTPUT:-
6 6 6
12 12 12
18 18 18

• Oindry

import java.util.Scanner;
public class PREP_p_37 {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int row = sc.nextInt();
int col = sc.nextInt();
int a[][]= new int[row][col];
int b[][]= new int[row][col];
int c[][]= new int[row][col];
for(int i =0;i<row;i++)
{
for(int j =0;j<col;j++)
{
a[i][j] = sc.nextInt();
}
}
for(int i =0;i<row;i++)
{
for(int j =0;j<col;j++)
{
b[i][j] = sc.nextInt();
}
}
int i=0,j=0,k=0;
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
c[i][j]=0;
for(k=0;k<col;k++)
{
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
System.out.print(c[i][j]+" ");
}
System.out.println();
}
}
}