Translate

important

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[100][100];
int arr[100][100];
int sum[100][100];
int a,b;
int r,c;
printf("Enter Rows in your matrix:");
scanf("%d",&r);
printf("\nEnter Columns in your matrix:");
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 [0][0]:1
Elements on [0][1]:2
Elements on [0][2]:3
Elements on [1][0]:4
Elements on [1][1]:5
Elements on [1][2]:6

Enter second matrix elements:
Elements on [0][0]:7
Elements on [0][1]:8
Elements on [0][2]:9
Elements on [1][0]:10
Elements on [1][1]:11
Elements on [1][2]: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

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Top Post Ad

Below Post Ad