#include <stdio.h>
#include <stdlib.h>
int main()
{
int m, n, p, q, i, j, k, a[10][10], b[10][10], c[10][10];
printf(“Enter the size of first matrix a\n”);
scanf(“%d%d”, &m, &n);
printf(“Enter the size of second matrix b\n”);
scanf(“%d%d”, &p, &q);
if (n != p)
{
printf(“Matix multiplication not possible\n”);
exit(0);
}
printf(“Enter the first matix elements a\n”);
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
scanf(“%d”, &a[i][j]);
}
}
printf(“The Matrix a is \n”);
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
printf(“%d\t”, a[i][j]);
}
printf(“\n”);
}
printf(“Enter the second matix elements b\n”);
for (i = 0; i < p; i++)
{
for (j = 0; j < q; j++)
{
scanf(“%d”, &b[i][j]);
}
}
printf(“The Matrix b is \n”);
for (i = 0; i < p; i++)
{
for (j = 0; j < q; j++)
{
printf(“%d\t”, b[i][j]);
}
printf(“\n”);
}
for (i = 0; i < m; i++)
{
for (j = 0; j < q; j++)
{
c[i][j] = 0;
for (k = 0; k < n; k++)
{
c[i][j] = c[i][j] + (a[i][k] * b[k][j]);
}
}
}
printf(“Resultant matrix c\n”);
for (i = 0; i < m; i++)
{
for (j = 0; j < q; j++)
{
printf(“%d\t”, c[i][j]);
}
printf(“\n”);
}
}
Develop a program to introduce 2D Array manipulation and implement Matrix multiplication and ensure the rules of multiplication are checked.
2 Answers