Computer Science, asked by Tauqeer2455, 10 months ago

Write A C Program To Find Subtraction Of Two Matrices

Answers

Answered by singhritesh1603
5

Answer:

This program allows the user to enter the number of rows and columns of two Matrices. Next, we are going to subtract one matrix from another matrix using C For Loop.

/* C Program to Subtract Two Matrices */

#include<stdio.h>

 

int main()

{

 int i, j, rows, columns, a[10][10], b[10][10];

 int Subtraction[10][10];

 

 printf("\n Please Enter Number of rows and columns  :  ");

 scanf("%d %d", &i, &j);

 

 printf("\n Please Enter the First Matrix Elements\n");

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

  {

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

    {

       scanf("%d", &a[rows][columns]);

    }

  }

   

 printf("\n Please Enter the Second Matrix Elements\n");

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

  {

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

    {

       scanf("%d", &b[rows][columns]);

    }

  }

 

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

  {

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

    {

       Subtraction[rows][columns] = a[rows][columns] - b[rows][columns];    

     }

  }

 

 printf("\n After Subtracting Matrix a from Matrix b = a - b \n");

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

  {

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

    {

       printf("%d \t ", Subtraction[rows][columns]);

    }

    printf("\n");

  }

 return 0;

Explanation:

Answered by unknownRU
0

Hope it helps!

Mark me as Brainlist!

Subtraction of two matrices in c programming

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int mat1[2][3],mat2[2][3],mat3[2][3],i,j;

printf("Enter the elements of matrix1\n");

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

{

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

{

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

}

}

printf("the elements of the matrix2\n");

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

{

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

{

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

}

}

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

{

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

{

mat3[i][j]=mat1[i][j]-mat2[i][j];

}

}

printf("\nthe result of matrix is\n");

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

{

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

{

printf(" %d",mat3[i][j]);

}

printf("\n");

}

getchar();

}

Similar questions