# Sum of 2 matrix in C

Hello, there today we learn about the 2 by 2 Matrix program in C Using the array Function. Sum of 2 matrix in c

## Addition of two matrices in c using 2d array

```#include <stdio.h>
void sumOfMatrices(int a[100][100],int b[100][100],int sum[100][100], int row, int col)
{
int i,j;
for (i = 0; i < row; ++i)
for (j = 0; j < col; ++j) {
sum[i][j] = a[i][j] + b[i][j];
}

}

void printSum(int sum[100][100], int row, int col){

int i,j;
printf("\nSum of two matrices: \n");
for (i = 0; i < row; ++i)
for (j = 0; j < col; ++j) {
printf("%d ", sum[i][j]);
if (j == col - 1) {
printf("\n\n");
}
}

}
int main()
{
int r, c, a[100][100], b[100][100], sum[100][100], i, j;
printf("Enter the number of rows ");
scanf("%d", &r);
printf("Enter the number of columns (between 1 and 100): ");
scanf("%d", &c);

printf("\nEnter elements of 1st matrix:\n");
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j)
{
printf("Enter element a%d%d: ", i + 1, j + 1);
scanf("%d", &a[i][j]);
}

printf("Enter elements of 2nd matrix:\n");
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j) {
printf("Enter element b%d%d: ", i + 1, j + 1);
scanf("%d", &b[i][j]);
}

sumOfMatrices(a,b,sum,r,c);

printSum(sum,r,c);

return 0;
}```

## Addition of 2 by 2 Matrix

Output

EXAMPLE

Input

Input matrix 1:

1     2

4     5

Input matrix 2:

9     8

3     2

Output

Sum of both matrices:

10    10

7       7

## Sum of matrices in C

Sum of user-defined Matrix in C (ClikHere)

How to Read file in C Program (ClikHere)

## Wap in C to find sum of 2d matrices

We highly recommend you for visiting this Here (click) if you don’t understand and you have to face any kind of Problem while Compiling this program. Sum of 2 matrix in C.

THANKS

This site uses Akismet to reduce spam. Learn how your comment data is processed.