Solved programming problem

How to add two 2D array in C.

Source code

#include <stdio.h>

int main()

{

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

    int i=0,j=0,r,c;

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

    scanf("%d %d",&r,&c);

    printf("Please Enter 1st %d X %d array: ",r,c);

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

    {

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

        {

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

        }

    }

    printf("Please Enter 2nd %d X %d array: ",r,c);

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

    {

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

        {

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

        }

    }

    ///add

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

    {

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

        {

            add[i][j]=array[i][j]+array1[i][j];

        }

    }

    ///printing add element

    printf("Your New add elements array: ");

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

    {

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

        {

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

        }

        printf("");

    }

    return 0;

}

Output

Please Enter Row and Column Number: 3 3


Please Enter 1st 3 x 3 array:


1 2 3

4 5 6

7 8 9


Please Enter 2nd 3 X 3 array:

9 8 7

6 5 4

3 2 1


Your New add elements array :


10 10 10

10 10 10

10 10 10

Join the discussion

Add your comment