Matrix:
There are some program given below for calculating the problems of matrix.
Program for calculating the sum of two matrix :
************************************************************
/* Program for calculating the sum of two matrix (2 rows 2 colum) */
#include
#include
void main()
{
int i,j;
int a[2][2], b[2][2], c[2][2];
clrscr();
/* Taking Value of Matrix A */
printf("Enter First Matrix A (2 rows 2 colums):\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf(" %d",& a[i][j]);
}
}
/* Taking value in Matrix B */
printf("Enter Second Matrix B (2 rows 2 colums):\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf(" %d",& b[i][j]);
}
}
/* Calculating Matrix C=Matrix A + Matrix B */
printf("\n\nThe Answer of A+B =\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf("%d\t",c[i][j]);
}
printf("\n");
}
getch();
}
******************************************************************************
Program for calculating the subtraction of two matrix :
*********************************************************
/*Program for calculating the subtruction of two matrix (2 rows 2 colum) */
#include
#include
void main()
{
int i,j;
int a[2][2], b[2][2], c[2][2];
clrscr();
/* Taking Value of Matrix A */
printf("Enter First Matrix A (2 rows 2 colums):\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf(" %d",& a[i][j]);
}
}
/* Taking value in Matrix B */
printf("Enter Second Matrix B (2 rows 2 colums):\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf(" %d",& b[i][j]);
}
}
/* Calculating Matrix C=Matrix A - Matrix B */
printf("\n\nThe Answer of A-B =\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=a[i][j]-b[i][j];
printf("%d\t",c[i][j]);
}
printf("\n");
}
getch();
}
*********************************************************