20_10

Write a C code to find the difference between two matrices of any order and print the result in matrix format.

 Source code:

/*Write a C code to find the difference between two matrices of any order and  print the result in matrix format.*/

#include <stdio.h>

int main()

{

        int row, col, i, j, first[10][10], second[10][10], difference[10][10]; 

printf("Enter the number of row & column:");

        scanf("%d %d", &row, &col);  

printf("Enter the 1st matrix:\n");

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

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

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

  printf("Enter the 2nd matrix:\n");

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

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

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

/* Find the difference of entered matrices and store it in difference[10][10] */

 

    for (i = 0; i < row; i++) {

    for (j = 0; j < col; j++) {

        difference[i][j] = first[i][j] - second[i][j];

     

    }

/*printing the difference array */

printf("Subtraction of two matrix is:\n");

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

{

    for (j = 0 ; j < col; j++){

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

}

printf("\n");

    }

return 0;

}

Output:

C code to find the difference between two matrices of any order and  print the result in matrix format


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...