Additing Two Matrices in C Programming


#include<stdio.h>
main()
{
int a[3][3],b[3][3],c[3][3];
int i,j,m=3,n=3;
//data for first matrix
printf("Enter a 3x3 matrix (1)\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
//data for second matrix
printf("Enter a 3x3 matrix (2)\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&b[i][j]);
}
}
//add the matrices
for(i=0;i<m;i++)
   {
   for(j=0;j<n;j++)
      {
      c[i][j]=a[i][j]+b[i][j];
      }
   }
//printing the matrix.
printf("The product matrix is :\n");
for(i=0;i<m;i++)
 {
  printf("\n");
for(j=0;j<n;j++)
{
printf("%d\t",c[i][j]);
}
 }
getch();
}

Comments

Popular posts from this blog

Migrating database from ASP.NET Identity to ASP.NET Core Identity

Customize User's Profile in ASP.NET Identity System

Lambda two tables and three tables inner join code samples