I have this code for matrix multiplication, but its given me a compilation error. I need t have a function that receives as arguments the pointers for the 3 matrices and their dimension N.
#include <stdio.h>
#define N 100
void matrixmul(int **matA, int **matB, int **matC, int n){
int i,j,k;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
matC[i][j] = 0;
for(k=0;k<n;k++){
matC[i][j] += matA[i][k] * matB[k][j];
}
}
}
}
int main(){
int matA[N][N]={1};
int matB[N][N]={3};
int matC[N][N];
int i,j,k;
matrixmul(&matA, &matB, &matC, N);
for(i=0;i<N;i++){
for(j=0;j<N;j++){
printf("%d ", matC[i][j]);
}
printf("\n");
}
return 0;
}
The error is:
teste.c: In function ‘main’:
teste.c:28:5: warning: passing argument 1 of ‘matrixmul’ from incompatible pointer type [enabled by default]
teste.c:5:6: note: expected ‘int **’ but argument is of type ‘int (*)[100][100]’
teste.c:28:5: warning: passing argument 2 of ‘matrixmul’ from incompatible pointer type [enabled by default]
teste.c:5:6: note: expected ‘int **’ but argument is of type ‘int (*)[100][100]’
teste.c:28:5: warning: passing argument 3 of ‘matrixmul’ from incompatible pointer type [enabled by default]
teste.c:5:6: note: expected ‘int **’ but argument is of type ‘int (*)[100][100]’