C program for addition of 2D matrix.

Posted by Mangesh on March 19, 2018

/* program in c for matrix multiplication. */

Skills Learning :

  1. Representation of 2D matrix.
  2. Looping.
  3. Matrix Addition.

Program :

#include<stdio.h>
#include<conio.h>
void main()
{
  int i,j,r,c;
  int a[20][20],b[20][20];
  printf("Enter the number of rows : ");
  scanf("%d",&r);
  printf("Enter the number of columns : ");
  scanf("%d",&c);
  printf("\t\tFirst matrix : \n");
  for(i=0;i<r;i++)
  {
    for(j=0;j<c;j++)
    {
       scanf("%d",&a[i][j]);
    }
  }
  printf("\t\tSecond matrix : \n");
  for(i=0;i<r;i++)
  {
    for(j=0;j<c;j++)
    {
      scanf("%d",&b[i][j]);
    }
  }
  printf("\t\tResultant matrix : \n");
  for(i=0;i<r;i++)
  {
    for(j=0;j<c;j++)
    {
       a[i][j] = a[i][j]+b[i][j];
       printf("%d ",a[i][j]);
    }
    printf("\n");
  }
  getch();
}

Output :

C program for matrix addition. Tested in Turbo C 3.2

Written with from Mangesh.

Related Post
1 C program to reverse element in array.
2 C program to find the smallest number in array.
3 C program to find the largest number in array.
4 C program for addition of 2D matrix.
5 C program to calculate sum of all elements in array.
Latest Post
1 C program to implement Queue using linked list.
2 C program for binary search tree (BST).
3 C program to search an element in linked list.
4 C program for postorder traversal in binary tree.
5 C program for preorder traversal in binary tree.