Addition of Two Matrix
![]()

Subtraction of Two Matrix

Multiplication of Two Matrix

WAP to add
two Matrixes.
#include <stdio.h>
void main()
{
int m, n, c, d,
first[10][10], second[10][10], sum[10][10];
printf("Enter the
number of rows and columns of matrix\n");
scanf("%d%d",
&m, &n);
Enter
the number of rows and columns of matrix
2 2 Enter the elements of first matrix
1 1
1 1
Enter the elements of second matrix
2 2
2 2
Elements of First matrix
1 1
1 1
Elements of Second matrix
2 2
2 2
Elements of Second matrix
3 3
3 3
printf("Enter the elements of first matrix\n");
for (c = 0; c < m; c++)
for (d = 0; d < n;
d++)
scanf("%d", &first[c][d]);
printf("Enter the
elements of second matrix\n");
for (c = 0; c < m; c++)
for (d = 0 ; d < n;
d++)
scanf("%d",
&second[c][d]);
/* Addition of Two
Matrix*/
for (c = 0; c < m; c++)
for (d = 0 ; d < n; d++)
sum[c][d] = first[c][d] +
second[c][d];
printf("\nElements of
First matrix\n");
for (c = 0; c < m; c++)
{
for (d = 0 ; d < n;
d++) printf("%d ",
first[c][d]);
printf("\n");
}
printf("\nElements of
Second matrix\n");
for (c = 0; c < m; c++)
{
for (d = 0 ; d < n;
d++) printf("%d ",
second[c][d]);
printf("\n");
}
printf("\nElements of Sum
matrix\n");
for (c = 0; c < m; c++)
{
for (d = 0 ; d < n;
d++) printf("%d ", sum[c][d]);
printf("\n");
}
}
WAP to multiply
two Matrixes.
#include <stdio.h>
void main()
{
int p, q, c, d, k;
int first[2][2],
second[2][2], multiply[2][2];
printf("Enter elements of first
matrix\n");
for (c = 0; c < 2; c++)
for (d = 0; d < 2; d++)
scanf("%d",
&first[c][d]);
printf("Enter elements of second
matrix\n");
for (c = 0; c < 2; c++)
for (d = 0; d < 2;
d++)
scanf("%d",
&second[c][d]);
for (c = 0; c < 2; c++)
for (d = 0; d < 2;
d++)
multiply[c][d] =0;
for (c = 0; c < 2; c++)
for (d = 0; d < 2;
d++)
for (k = 0; k < 2;
k++)
multiply[c][d]=
multiply[c][d] + first[c][k]*second[k][d];
printf("Product of
the matrices:\n");
for (c = 0; c < 2; c++)
{
for (d = 0; d < 2;
d++)
printf("%d ",
multiply[c][d]);
printf("\n");
}
}
Output
Enter elements of first matrix
1 2
3 4
Enter elements of second matrix
5 6
7 8
Product of the matrices:
19 22
43 50