Thursday 25 August 2016

C program to find the sum of two matrices of order mxn.

#include<stdio.h>
void main()
{
   int i,j,a[20][20],b[20][20],s[20][20],max,m,n;
   printf("Name: Viraj Singh\nRoll No.:-1503213117\n\n");
   printf("Enter order of the matrix\n");
   scanf("%d%d",&m,&n);
   printf("Enter the matrix A\n");
   for(i=0;i<m;i++)
       for(j=0;j<n;j++)
       scanf("%d",&a[i][j]);
   printf("Enter the matrix B\n");
   for(i=0;i<m;i++)
       for(j=0;j<n;j++)
       scanf("%d",&b[i][j]);
   for(i=0;i<m;i++)
   {
       for(j=0;j<n;j++)
       {
           s[i][j]=a[i][j]+b[i][j];
       }
   }
   printf("Sum is:-\n");
   for(i=0;i<m;i++)
   {
       for(j=0;j<n;j++)
       printf("%d   ",s[i][j]);
       printf("\n");
   }

}

No comments:

Post a Comment