Write a program to add two matrices

Source Code

#include<stdio.h>
#include<conio.h>
int main (int argc, char *argv[])
{
  clrscr();
  int m1[10][10];
  int m2[10][10];
  int s[10][10];
  int i,j,r,c;
  for(i=0;i<10;i++)
  {
      for(j=0;j<10;j++)
      {
      m1[i][j]=0;
      m2[i][j]=0;
      s[i][j]=0;
      }
  }
  printf("\n Enter size of row and colomn:");
  scanf("%d %d",&r,&c);
  printf("\n Enter the two matrices: \n");
  for(i=0;i<r;i++)
  {
      for(j=0;j<c;j++)
      {
    printf("Enter element %d %d of m1: ",(i+1),(j+1));
    scanf("%d",&m1[i][j]);
    printf("Enter element %d %d of m2: ",(i+1),(j+1));
    scanf("%d",&m2[i][j]);
      }
  }
  printf("\n The first matrix is: \n");
  for(i=0;i<r;i++)
  {
      for(j=0;j<c;j++)
      {
     printf("%d ",m1[i][j]);
      }
      printf("\n");
  }
  printf("\n The second matrix is: \n");
  for(i=0;i<r;i++)
  {
      for(j=0;j<c;j++)
      {
     printf("%d ",m2[i][j]);
      }
      printf("\n");
  }
  printf("\n Sum of matrices is: \n");
  for(i=0;i<r;i++)
  {
      for(j=0;j<c;j++)
      {
     s[i][j]=m1[i][j]+m2[i][j];
     printf("%d ",s[i][j]);
      }
      printf("\n");
  }
  getch();
}

Find More from our code collection
Armstrong number, binary number to a decimal number, bubble sort, decimal number to binary number, factorial of the given number factors, fibonacci numbers, HCF and LCM, matrix, mergesort, salary of the employee. palindrome, quadratic equation, star patterns, series etc. and much more...
#Return to Example Source Code