Showing posts with label Program to find sum and difference of two matrices. Show all posts
Showing posts with label Program to find sum and difference of two matrices. Show all posts

Wednesday, July 20, 2011

Program to find sum and difference of two matrices

/*Serial No.88     [swami63.cpp]*/

#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();
}