Solved programming problem

Multiply 2D array in C.

Source code

#include <stdio.h>

int main()

{

    int array[100][100],array1[100][100];

    int multiply[100][100];

    int row,col,i,j,a,sum;

    printf("Please Enter The Row and Column Number: ");

    scanf("%d %d",&row,&col);

    printf("Enter elements in Array 1 of size %d x %d: 
",row,col);

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

    {

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

        {

            scanf("%d",&array[i][j]);

        }

    }

    printf("
Enter elements in Array 2 of size %d x %d: 
",row,col);

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

    {

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

        {

            scanf("%d",&array1[i][j]);

        }

    }

    ///Multiply both array

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

    {

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

        {

            sum = 0;

            for(a=0;a<row;a++)

            {

                sum += array[i][a] * array1[a][j];

            }

            multiply[i][j] = sum;

        }

    }

    printf("
Product of array 1 and array 2 = 
");

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

    {

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

        {

            printf("%d ",multiply[i][j]);

        }

        printf("
");

    }

    return 0;

}

Output

Please Enter The Row and Column Number: 3 3

Enter elements in Array 1 of size 3 x 3:

1 2 3

4 5 6

7 8 9

Enter elements in Array 2 of size 3 x 3:

9 8 7

6 5 4

3 2 1

Product of array 1 and array 2 =

30 24 18

84 69 54

138 114 90

Join the discussion

Add your comment