Q:

C Program to subtract two matrices

0

C Program to subtract two matrices

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>

#define SIZE 3 
int main()
{
    int A[SIZE][SIZE];  // Matrix 1
    int B[SIZE][SIZE];  // Matrix 2
    int C[SIZE][SIZE];  // Resultant matrix

    int row, col;

   
    printf("Enter elements in matrix A of size 3x3: \n");
    for(row=0; row<SIZE; row++)
    {
        for(col=0; col<SIZE; col++)
        {
            scanf("%d", &A[row][col]);
        }
    }

    
    printf("\nEnter elements in matrix B of size 3x3: \n");
    for(row=0; row<SIZE; row++)
    {
        for(col=0; col<SIZE; col++)
        {
            scanf("%d", &B[row][col]);
        }
    }

    for(row=0; row<SIZE; row++)
    {
        for(col=0; col<SIZE; col++)
        {
            /* Cij = Aij - Bij */
            C[row][col] = A[row][col] - B[row][col];
        }
    }

    
    printf("\nDifference of two matrices A-B = \n");
    for(row=0; row<SIZE; row++)
    {
        for(col=0; col<SIZE; col++)
        {
            printf("%d ", C[row][col]);
        }
        printf("\n");
    }

    return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now