I'm adding two matrices by calling a function in C but I cannot make it work. Can anyone tell me what is wrong in my code?
//Program to print the sum of 2 matrices
#include<stdio.h>
#include<stdlib.h>
//fucntion to fetch matrix from user
void getMatrix(int** firstMatrix, int row, int col){
int i,j;
for(i = 0; i < row ; i++){
for(j = 0; j < col; j++){
scanf("%d",firstMatrix[i][j]);
}
}
}
int main(int argc, char *argv[]){
int matrixDim,i,j;
printf("Enter the dimensions\n");
scanf("%d",&matrixDim);
int firstMatrix[matrixDim][matrixDim];
int secondMatrix[matrixDim][matrixDim];
printf("Enter the elements of 1st matrix\n");
getMatrix(firstMatrix,matrixDim,matrixDim);
printf("Enter the elements of 2nd matrix\n");
getMatrix(secondMatrix,matrixDim,matrixDim);
//to print the sum of matrices
printf("Sum of given matrices is\n");
for(i = 0; i < matrixDim; i++){
for(j = 0; j < matrixDim; j++){
printf("%d\t",firstMatrix[i][j]+secondMatrix[i][j]);
}
printf("\n");
}
return EXIT_SUCCESS;
}
I'm getting the following warnings: Passing argument 1 of 'getMatrix' from incompatible type.
After running the code, I am not able to read the matrix elements through the function, the program stops working and ends.