This is C Program to Sum of Two Matrix. In this program user asks to add two matrixes. The array type variables are declared for containing the value. Here loop statement comes in use for laying the condition true nested for loop used for print the matrix in it. Then after the condition as follows the loop statement value is been entered for 2×2 matrix to print. Then another for loop to add the both matrix on it. And display the result on screen.
Problem Statement:
This is C program to add two Matrices.
- Declare the variables.
- Using the loop statement.
- Display the result on the screen.
Here is source code of the C program to add two Matrices. The C program is successfully compiled. The program output is also shown below.
#include<stdio.h>
void main()
{
int a[2][2],b[2][2],c[2][2],i,j;
clrscr();
printf("Enter the value of First 2 x 2 Matrix : ");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the value of Second 2 x 2 Matrix : ");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=a[i][j]*b[i][j];
printf("Sum of Two Matrix : %d\n",c[i][j]);
}
}
getch();
}