Subtraction of two matrix – C Program

Subtraction of two matrix – C Program

write a c program to display difference of given two matrix.

#include <stdio.h>
#include <conio.h>
 
void main()
{
int first[10][10],second[10]10],result[10][10], i, j, row, col;
 
printf("Enter the row size of matrix : \n");
scanf("%d",&row);
 
printf("Enter the column size of matrix : \n\n");
scanf("%d",&col);
 
printf("Enter the elements of First matrix :\n");
for(i=0;i<row;i++)
{
  for(j=0;i<col;j++)
    {
      scanf("%d", &first[i][j]);
    }
 
}    
 
printf("\nEnter the elements of Second matrix :\n");
for(i=0;i<row;i++)
{
  for(j=0;i<col;j++)
    {
      scanf("%d", &second[i][j]);
    }
 
}  
 
for(i=0;i<row;i++)
{
  for(j=0;i<col;j++)
    {
    result[i][j]=first[i][j] - second[i][j];
    }
}    
 
printf("\n\nThe Difference of two matrix is : \n")
for(i=0;i<row;i++)
{
  for(j=0;i<col;j++)
    {
      printf("%d", result[i][j]);
     printf("\t");  
    }
printf("\n");  
}    
}

The output of subtraction of two matrix is :

Enter the row size of matrix :
3
Enter the column size of matrix :
3
 
Enter the elements of first matrix :
6
2
5
4
8
6
9
8
9
 
Enter the elements of second matrix :
1
2
1
4
4
2
8
9
6
 
The Difference of two matrix is :
5    0    4
0    4    4
1   -1   -3

 

Leave a Reply

Your email address will not be published. Required fields are marked *