‘C’ program to add two matrices of order m X n.

C File =>



/* Write a ‘C’ program to add two matrices
of order mXn */

#include<stdio.h>
int main() 
{
     int m,n,i,j,mat1[20][20];
     int mat2[20][20],add[20][20];
 
     printf("\n Enter no. of rows : ");
     scanf("%d",&m);
     printf("\n Enter no. of cols : ");
     scanf("%d",&n);
 
     printf("\n Input Matrix1 : \n");
     for(i=0;i<m;i++)
    {
       for(j=0;j<n;j++)
      {
           printf("\n Enter element %d%d : ", i+1,j+1);
           scanf("%d",&mat1[i][j]);
      }
   }
 
     printf("\n Input Matrix2 : \n");
     for(i=0;i<m;i++)
    {
        for(j=0;j<n;j++)
       {
          printf("\n Enter element %d%d : ", i+1,j+1);
          scanf("%d",&mat2[i][j]);
        }
     }
 
      printf("\n\n Addition Matrix is :\n");
      for(i=0;i<m;i++)
     {
        for(j=0;j<n;j++)
       {
             add[i][j]=mat1[i][j]+mat2[i][j];
             printf("%d\t",add[i][j]);
        }
        printf("\n");
     }
 
     return 0;
}

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.