Hey I have a problem here. Maybe someone can figure it out
This is my code and it's not giving me the right output
Code:
#include <stdio.h>
int main()
{
int dim;
int i, row, col;
// inputting matrices dimensions
int M0, M1, M2;
// Calculate the product
scanf("%d", &dim);
for (row=1; row<=dim; row++)
{
for (col=1; col<=dim; col++)
{
//Calculate (row,column) element of the product
M2 = 0;
for (i=1; i<=dim; i++)
{
// Element in M0 at (row,i)
M0=(row+1)*(col+1);
// Element in M1 at (i, column)
M1=row+col;
M2+=M0*M1; // The calculation
}
// prining an element
printf("%d\t", M2);
}
// Going to the next row
printf("\n");
}
return 0;
}
The output should give me this:
Input
2
Correct Output
2 5
4 10