# Sum of matrix in C and Addition of 3 Matrices using Array

## Sum of Matrix in C

Here we learn the addition of Matrix in C other words Sum of User choices matrices that mean you can decide the size of the matrix (Value of Row & Column)

```#include<stdio.h>
int main()
{
int r, c, a, b, sum, 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]);
}
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j) {
sum[i][j] = a[i][j] + b[i][j];
}
printf("\nSum of two matrices: \n");
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j) {
printf("%d ", sum[i][j]);
if (j == c - 1) {
printf("\n\n");
}
}

return 0;
}```

Output

Enter the number of ROWS & COLUMNS (between 1 and 100): 3 × 3

Enter elements of 1st matrix:

M a1 a2  a3
a1 1   2    3
a2 1   2    3
a3 4   5    6

Format of Element are :-
Enter element a11: Enter element a12: Enter element a13: ( 1   2    3)

Enter element a21: Enter element a22: Enter element a23: ( 1   2    3)

Enter element a31: Enter element a32: Enter element a33: (4   5    6)

Note :- M for Nothing,(it’s false)

Enter elements of 2nd matrix:

M   b11   b22    b33
b11  6      3        2
b22  6      7        9
b33  8      9        2

Enter element b11: Enter element b12: Enter element b13: (6      3        2)

Enter element b21: Enter element b22: Enter element b23: (6      7        9)

Enter element b31: Enter element b32: Enter element b33: (8      9        2)

## Sum of two matrix in C Try to understand this code, it will help you in understanding that how metrics work for printing their value Sum of matrix in C Here we use Array Function for inputting the Matrix Data. It is a simple Matrix Program where you input any Random Matrix Element, and it will also Re-Defined in Matrix form.

## Matrix Program in C using Array

That is enough for Understanding How matrices work in C programming language while using For() loop Sum of matrix in C Try to understand this code, it will help you in understanding that how metrics work for printing their value Sum of matrix in C. You need to Understand, How array works (ReadHere)

```#include<stdio.h>

main()
{
int i,j;
int a,b,c;
int matrix;
printf(“input in matrix form\n”);
for(i=0;i<3; i++){
scanf(“%d%d%d”,&a,&b,&c);
for( j=0;j<3;j++){

if(j==0)
matrix[i][j]=a;
else if(j==1)
matrix[i][j]=b;
else if(j==2)
matrix[i][j]=c;
}
}

// print
printf(“ouput in matrix form\n”);
for(i=0;i<3; i++){

for( j=0;j<3;j++){
printf(“%d “,matrix[i][j]);
}
printf(“\n”);
}
}```

Output

Input in matrix form (It will pick randomly)
1 2 3 4 5 6 7 8 9 but output is still in matrix form

1 2 3

4 5 6

7 8 9

That means you entered your value in any form (sequence) it will automatically generate a Matrices view.

VISIT

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