0

|55|error: incompatible type for argument 1 of 'det'

#include <stdio.h> #if !defined(N) #define N 3 #endif double det(double A[N][N], int dim); int main(void) { int dim, j, k; double A[N][N], det_value; dim = N; printf("Matrix A is\n"); for (j = 0; j < N; j++) { for (k = 0; k < N; k++) { printf(" %g", A[j][k]); } printf("\n"); } det_value = det(A[N][N], dim); printf("det(A) = %g\n", det_value); return 0; } double det(double A[N][N], int dim) { int i, a, b; double ce, temp, value, sum_value; if (dim == 2) { return A[0][0] * A[1][1] - A[0][1] * A[1][0]; } else { ce = 1; for (i = 0; i < dim; i++){ for (a = 0; a < dim; a++) { if (a != i) { for (b = 1; b < dim; b++) { if (a < i) { temp = A[i][0]; A[a][b] = A[a + 1][b]; value = ce * temp * det(A[N-1][N-1], dim - 1); sum_value += value; ce *= (-1); } else if (a > i) { temp = A[i][0]; A[a][b] = A[a + 1][b + 1]; dim--; value = ce * temp * det(A[N-1][N-1], dim - 1); sum_value += value; ce *= (-1); } } } } } return sum_value; } } /* I'm doing a calculation of a matrix, and I have no idea why it is keep showing the "incompatible type error" messeges. Can anyone help me figure it out ? I will be appreciated. */

20th Nov 2021, 2:19 AM
Nathan Lo
Nathan Lo - avatar
1 Réponse
+ 2
I dont know what you are expecting through this program i haven't seen your logics i have analyse your some of the mistakes. First thing in line number 23 det_value = det(A[N][N], dim); Here you just need to pass the name of array det_value = det(A, dim); Then inside the function definition of det check inside of second if condition you have written det(A[N-1][N-1] ,dim-1) Here u need to pass a and b i guess u need to pass value same do for other array
20th Nov 2021, 3:47 AM
A S Raghuvanshi
A S Raghuvanshi - avatar