Problem 37

2 comments on “Problem 37”


  • 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();
    }
    }
    }