In this C program we will get two matrix as input from user and the program will calculate the sum of both matrix and display the sum as output.
For writing this program, you need to have knowlegde of following concepts
Algorithm to input and add two matrix and display as output
- START
- Input the matrix 1 elements.
- Input the matrix 2 elements.
- Repeat from i = 0 to 3
- Repeat from j = 0 to 3
- mat3[i][j] = mat1[i][j] + mat2[i][j]
- Print mat3.
- STOP
C Program to input and add two matrix and display as output
#include<stdio.h>
#include<conio.h>
int main()
{
int i, j, mat1[3][3], mat2[3][3];
printf("Enter first matrix: \n");
for(i = 0; i < 3; i++)
{
for(j = 0; j < 3; j++)
{
scanf("%d", &mat1[i][j]);
}
}
printf("\nEnter second matrix: \n");
for(i = 0; i < 3; i++)
{
for(j = 0; j < 3; j++)
{
scanf("%d", &mat2[i][j]);
}
}
printf("\nmat1 + mat2 = \n");
for(i = 0; i < 3; i++)
{
for(j = 0; j < 3; j++)
{
printf("%d ", mat1[i][j] + mat2[i][j]);
}
printf("\n");
}
getch();
}
Output of Program

Download Files: