Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

// Matrix Subtraction program

#include<stdio.h>

int main()
{
int a[3][3];
int b[3][3];
int c[3][3];
int i,j;

printf("Enter the elements of matrix a: \n");


for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("a[%d][%d] = ",i,j);
scanf("%d",&a[i][j]);
}
}

printf("Enter the elements of matrix b: \n");


for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("b[%d][%d] = ",i,j);
scanf("%d",&b[i][j]);
}
}

//Display both matrices


printf("FIRST MATRIX\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("\t\t");
printf("%d",a[i][j]);
}
printf("\n");
}

printf("\n\n");

printf("SECOND MATRIX\n");

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("\t\t");
printf("%d",b[i][j]);
}
printf("\n");
}

// MATRIX SUBTRACTION
printf("\n\nSubtraction of matrices\n\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("\t\t");
c[i][j]=a[i][j]-b[i][j];
printf("%d",c[i][j]);
}
printf("\n");
}

return 0;
}

You might also like