Hi, everyone. I am trying to write a program that read two matrices (one in each function), and then calculates the product between the first and the second (in a function designed for that purpose only), and displays the result in the main function. However, when I compile the program, I get errors, and I believe I am making mistakes when I return each matrix to the main function, and also when I pass each matrix to a function, for example, matrices 1 and 2 to the function product(). Am I right, or my mistakes are far from that? Thanks in advance!

Code:

#include <stdio.h>
double read_matrix1 (double matrix1[2][2]);
double read_matrix2 (double matrix2[2][2]);
double product (double matrix1[2][2], double matrix2[2][2], double matrix3[2][2]);
int main (void)
{
double matrix1[2][2], matrix2[2][2], matrix3[2][2];
int i, j;
matrix1 = read_matrix1(matrix1);
matrix2 = read_matrix2(matrix2);
matrix3 = product(matrix1, matrix2);
printf("The product of the two matrices yields:\n");
for (i = 0 ; i < 2 ; i++)
{
for (j = 0 ; j < 2 ; j++)
{
printf("%f ", matrix3[i][j]);
}
printf("\n");
}
return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double read_matrix1 (double matrix1[2][2])
{
int i, j;
printf("Input of matrix 1 elements.\n");
for (i = 0 ; i < 2 ; i++)
{
for (j = 0 ; j < 2 ; j++)
{
printf("Type in the element [%d][%d]: ", i, j);
scanf("%lf", &matrix1[i][j]);
}
}
return matrix1[2][2];
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double read_matrix2 (double matrix2[2][2])
{
int i, j;
printf("Input of matrix 2 elements.\n");
for (i = 0 ; i < 2 ; i++)
{
for (j = 0 ; j < 2 ; j++)
{
printf("Type in the element [%d][%d]: ", i, j);
scanf("%lf", &matrix2[i][j]);
}
}
return matrix2[2][2];
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double product(double matrix1[2][2], double matrix2[2][2], double matrix3[2][2])
{
int i, j, k;
double sum, total = 0;
for (i = 0 ; i < 2 ; i++)
{
for (j = 0 ; j < 2 ; j++)
{
for (k = 0 ; k < 2 ; k++)
{
sum = matrix1[i][k] * matrix2[k][j];
total = total + sum;
}
matrix3[i][j] = total;
sum = 0;
}
}
return matrix3[2][2];
}