Search This Blog

Wednesday, 15 December 2021

10. C Program to perform addition and subtraction of Matrices .

 /*10. C Program to perform addition and subtraction of Matrices */

#include<stdio.h>

void main()

{

     int a[10][10],b[10][10],add[10][10],sub[10][10],i,j,m,n;

     clrscr();

     printf("Enter the order of matrix\n");

     scanf("%d%d",&m,&n);

     printf("Enter the elements of first matrix:\n");

     for(i=0;i<m;i++)

     {

          for(j=0;j<n;j++)

          {

              scanf("%d",&a[i][j]);

          }

     }

     printf("Enter the elements of second matrix:\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++)

          {

              add[i][j]=a[i][j]+b[i][j];

              sub[i][j]=a[i][j]-b[i][j];

          }

     }

     printf("Matrix Addition:\n");

     for(i=0;i<m;i++)

     {

          for(j=0;j<n;j++)

          {

              printf("%d\t",add[i][j]);

          }

          printf("\n");

     }

     printf("Matrix Subtraction:\n");

     for(i=0;i<m;i++)

     {

          for(j=0;j<n;j++)

          {

              printf("%d\t",sub[i][j]);

          }

          printf("\n");

     }

     getch();

}

No comments :

Post a Comment

FREE Hit Counters