# How to print sum of two matrices using c programming?|C program to find sum of two matrices

In this article I am going to share the source code of the C programming language to find the sum of two matrices.

Q. How do you find the sum of two matrices in C?

or,

Addition of two matrix in c using array?

or,

Addition of two matrix in c using 2d array?

or,

Write a program to find the sum of two matrices?

or,

Matrix program in C

To find sum of two matrices in C programming you should know some topic of C which is given below.

• Simple c program
• Operators in c
• Scanf() & Printf()
• If statement in c
• Loop in c
• Multidimensional array.

### C program to find sum of two matrices

I am assuming here that you have studied the above topics let's see the C program to find sum of two matrices.

``````#include<stdio.h>
int main()
{
int ar;
int arr;
int sum;
int a,b;
int r,c;
scanf("%d",&r);
scanf("%d",&c);
printf("\n\nEnter First matrix Elements\n");
for(a=0; a<r; a++)
{
for(b=0; b<c; b++)
{
printf("Element on [%d][%d]\n",a,b);
scanf("%d",&ar[a][b]);
}
}
printf("\nEnter second matrix Elements\n");
for(a=0; a<r; a++)
{
for(b=0; b<c; b++)
{
printf("Element on [%d][%d]\n",a,b);
scanf("%d",&arr[a][b]);
}
}
for(a=0; a<r; a++)
{
for(b=0; b<c; b++)
{
sum[a][b]=ar[a][b]+arr[a][b];
}
}
printf("\nPrinting Sum of Both matrixes:\n");
for(a=0; a<r; a++)
{
for(b=0; b<c; b++)
{
printf("%d ",sum[a][b]);
if(b==c-1)
{
printf("\n");
}
}
}
return 0;
}``````

OUTPUT

Enter Rows in Your Matrix: 2
Enter Columns in Your matrix: 3
Enter first matrix elements
Elements on :1
Elements on :2
Elements on :3
Elements on :4
Elements on :5
Elements on :6

Enter second matrix elements:
Elements on :7
Elements on :8
Elements on :9
Elements on :10
Elements on :11
Elements on :12

Printing sum of both matrixes:
8 10 12
14 16 18

This is the source code of C programming language to print sum of two matrices.I hope you will have understand the code and how it works..

If you have any queries related to this code than please comment below i will try my best to give you the best possible answer. Thank You!

Tags