Subtraction of matrix

                     
                       Subtraction of matrix

Subtraction of matrix means that one matrix is subtracted for another and result is putted into third matrix.
C program to subtract matrix:-
 
#include <stdio.h>
#include <conio.h>

void main()
{
 int a[3][3],b[3][3],c[3][3],i,j,k;
 clrscr();
 printf("\n\t Enter First Matrix : ");
 for(i=0;i<3;i++)
 {
  for(j=0;j<3;j++)
  {
   scanf("%d",&a[i][j]);
  }
 }
 printf("\n\t Enter Second Matrix : ");
 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]=0;
   for(k=0;k<3;k++)
   {
   c[i][j]=c[i][j]+a[i][k]*b[k][j];
   }
  }
 }
 printf("\n\t Matrix Multiplication is : \n\n");
 for(i=0;i<3;i++)
 {
  for(j=0;j<3;j++)
  {
   printf("\t %d",c[i][j]);
  }
  printf("\n");
 }
 getch();
}

Output:-

Enter First Matrix : 2 1 2
 3 2 1
 2 3 3
 
 Enter Second Matrix : 2 1 0
 2 3 0
 1 1 2
 
 Matrix Subtraction is :
 
 0 0 2
 1 -1 1
 1 2 1

Comments

  1. write a program to read a matrix of size m×n enteed by the user, and display its transpose matrix

    ReplyDelete

Post a Comment

Popular posts from this blog