#include <iostream>
using namespace std;
void readMatrixA(int lenght)
{
int matrixA[101][101];
for (int i = 0; i < lenght; i++)
for (int j = 0; j < lenght; j++)
cin >> matrixA[i][j];
}
void readMatrixB(int lenght)
{
int matrixB[101][101];
for (int i = 0; i < lenght; i++)
for (int j = 0; j < lenght; j++)
cin >> matrixB[i][j];
}
void matrixMultiplication(int matrixA[101][101], int matrixB[101][101],int lenght)
{
int i, j, matrixC[101][101];
if (lenght <= 2)
{
for (i = 0; i < lenght; i++)
for (j = 0; j < lenght; j++)
{
matrixC[i][j] = 0;
for (int k = 0; k < lenght; k++)
matrixC[i][j] += matrixA[i][k] * matrixB[k][j];
}
}
else
{
matrixC[1][1]=matrixMultiplication(matrixA[1][1], matrixB[1][1], lenght / 2) + matrixMultiplication(matrixA[1][2], matrixB[2][1], lenght / 2);
matrixC[1][2]=matrixMultiplication(matrixA[1][1], matrixB[1][2], lenght / 2) + matrixMultiplication(matrixA[1][2], matrixB[2][2], lenght / 2);
matrixC[2][1]=matrixMultiplication(matrixA[2][1], matrixB[1][1], lenght / 2) + matrixMultiplication(matrixA[2][2], matrixB[2][1], lenght / 2);
matrixC[2][2]=matrixMultiplication(matrixA[2][1], matrixB[1][2], lenght / 2) + matrixMultiplication(matrixA[2][2], matrixB[2][2], lenght / 2);
}
for (i = 0; i < lenght; i++)
{
for (j = 0; j < lenght; j++)
{
cout << matrixC[i][j] << " ";
}
cout << endl;
}
}
int main()
{
int lenght;
cout << "Introduceti dimensiunea matricelor: "; cin >> lenght;
int matrixA[101][101], matrixB[101][101], matrixC[101][101];
cout << "Introduceti matricea A: ";
readMatrixA(lenght);
cout << "Introduceti matricea B: ";
readMatrixB(lenght);
matrixMultiplication(matrixA, matrixB, lenght);
return 0;
}
This is a code for Strassen's matrix multiplication written in visual studio. The code is using divide and conquer technique for square matrix.
Inside the "matrixMultiplication" function, where are those 4 rows of calls, i have this error "argument of type "int" is incompatible with parameter of type "int(*)[101]"" and i don't know what to do.
Those are the rows with error.
matrixC[1][1]=matrixMultiplication(matrixA[1][1], matrixB[1][1], lenght / 2) + matrixMultiplication(matrixA[1][2], matrixB[2][1], lenght / 2);
matrixC[1][2]=matrixMultiplication(matrixA[1][1], matrixB[1][2], lenght / 2) + matrixMultiplication(matrixA[1][2], matrixB[2][2], lenght / 2);
matrixC[2][1]=matrixMultiplication(matrixA[2][1], matrixB[1][1], lenght / 2) + matrixMultiplication(matrixA[2][2], matrixB[2][1], lenght / 2);
matrixC[2][2]=matrixMultiplication(matrixA[2][1], matrixB[1][2], lenght / 2) + matrixMultiplication(matrixA[2][2], matrixB[2][2], lenght / 2);
In your
MatrixMultiplication()function you return avoid, but your program is waiting for it to return anint. You need to changeMatrixMultiplicationto return an int.