How to add two Matrices in c program

      No Comments on How to add two Matrices in c program

Add two matrices in c program

#include<stdio.h>
#include<conio.h>
void main()
{
 int a[3][3],b[3][3],c[3][3],i,j;
 clrscr();
 printf("Enter First Matrice row wise:-\n");

 for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
    {
     scanf("%d",&a[i][j]);
    }
  }

  printf("Enter Second Matrice row wise:-\n");

 for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
    {
     scanf("%d",&b[i][j]);
    }
  }



 for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
    {
     c[i][j]=a[i][j]+b[i][j];
    }
  }

  printf("Sum of Matrice is:-\n");
  for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
    {
     printf("%d ",c[i][j]);

    }
    printf("\n");
  }
 getch();
}

OUTPUT:-

add two matrices in c program

Leave a Reply

Your email address will not be published. Required fields are marked *