Program to add the given two matrices
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int mata[10][10], matb[10][10], matc[10][10];
int i, j, row, col;
clrscr();
printf("Enter the order of the matrix : ");
scanf("%d %d", &row, &col);
printf("\nEnter the elements of first matrix : \n\n");
for(i = 0; i < row; i++)
for(j = 0; j < col; j++)
scanf("%d", &mata[i][j]);
printf("\nEnter the elements of second matrix : \n\n");
for(i = 0; i < row; i++)
for(j = 0; j < col; j++)
scanf("%d", &matb[i][j]);
for(i = 0; i < row; i++)
for(j = 0; j < col; j++)
matc[i][j] = mata[i][j] + matb[i][j];
printf("\nThe resultant matrix is : \n\n");
for(i = 0; i < row; i++)
{
for(j = 0; j < col; j++)
{
printf("%d \t", matc[i][j]);
}
printf("\n");
}
getch();
}
Output:
Enter the order of the matrix : 3 3
Enter the elements of first matrix :
1 3 5
7 9 11
13 15 17
Enter the elements of second matrix :
2 4 6
8 10 12
14 16 18
The resultant matrix is :
3 7 11
15 19 23
27 31 35
-
UpdatedDec 31, 2019
-
Views5,141
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order