I am unable to input the correct form for matrices multiplication. I have an exam tomorrow in which I need to use this. Please help me.
Code:
#include <stdio.h>
#include <conio.h>
int main()
{
float a[10][10], b[10][10], c[10][10];
int i, j, k, l, n=0, m=0, x=0, y=0, sum=0;
printf("Enter the number of rows and collumns of the first matrix");
scanf("%d %d", &n, &m);
printf("What are the elements of the first matrix?\n");
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
scanf("%f", &a[i][j]);
}
}
printf("Enter the number of rows and collumns of the second matrix");
scanf("%d %d", &k, &l);
if (m != l)
{
printf("these matrices cannot be multiplied");
}
else
{
printf("What are the elements of the second matrix?\n");
for (i = 0; i < k; i++)
{
for (j = 0; j < l; j++)
{
scanf("%f", &b[k][l]);
}
}
printf("Your matrices are \n");
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
printf("%f ", a[i][j]);
}
printf("\n");
}
printf("\n");
for (i = 0; i < k; i++)
{
for (j = 0; j < l; j++)
{
printf("%f ", b[k][l]);
}
printf("\n");
}
printf("\n");
for (i = 0; i < n; i++)
{
for (j = 0; j < k; j++);
{ sum = 0;
for (x = 0; x < l; x++)
{
sum += a[i][x] * b[x][j];
}
c[i][j] = sum;
sum = 0;
}
}
printf("\n");
printf("The multiplication of the matrices is");
for (i = 0; i < n; i++)
{
for (j = 0; j < l; j++)
{
printf("%f\t", c[i][j]);
printf("\t");
}
printf("\n");
}
printf("\n");
}
getch();
}