C Program To Find Sum and Difference Of Two Matrices

How to write a C Program To Find Sum and Difference Of Two Matrices in C Programming Language ?


Solution For C Program :

/*C Program To Find Sum and Difference Of Two Matrices.*/

#include<stdio.h>
#include<conio.h>
void main()
{
int mat1[3][2],mat2[3][2];
int i,j;
clrscr();
printf("enter the Ist matrix\n");
for(i=0;i<3;i++)
    {
    for(j=0;j<2;j++)
        {
        scanf("%d",&mat1[i][j]);
        }
    }
printf("\n\n\nFirst Entered matrix is:\n");
for(i=0;i<3;i++)
    {
    printf("\n");
    for(j=0;j<2;j++)
        {
        printf("%d\t",mat1[i][j]);
        }
    }
printf("\n\nEnter the 2nd matrix\n");
for(i=0;i<3;i++)
    {
    for(j=0;j<2;j++)
        {
        scanf("%d",&mat2[i][j]);
        }
    }
printf("\n\n\nSecond Entered matrix is:\n");
for(i=0;i<3;i++)
    {
    printf("\n");
    for(j=0;j<2;j++)
        {
        printf("%d\t",mat2[i][j]);
        }
    }

printf("\n\n Sum of the two matrix is:\n");
for(i=0;i<3;i++)
    {
    printf("\n");
    for(j=0;j<2;j++)
        {
        printf("%d\t",mat2[i][j]+mat1[i][j]);
        }
    }
printf("\n\n Difference of the two matrix is:\n");
for(i=0;i<3;i++)
    {
    printf("\n");
    for(j=0;j<2;j++)
        {
        printf("%d\t",mat1[i][j]-mat2[i][j]);
        }
    }
getch();
}

You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable


Learn More :