I'm having a problem with my schooljob where I have to do in C, which consists of, get the inverse array through the enclosed array. Every time I try to call a function that have a array as parameter, that error apear "Row 37 [Error] incompatible type for argument 2 of 'Invertible'".
So far this is what I could produce in C# and then I tried to rewrite it in C, but I'm not getting success because I do not know the language.
I'm using DEV C++ to compile my code
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int mult = 0;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
float detLaplace(int n, float a[n][n]);
float det2(float array[2][2]);
float det3(float array[3][3]);
float * cafactor(int n, float array[n][n], int Row,int Column);
float * matcafactor(int n, float a[n][n]){
float * Transpose(int n, float array[n][n]);
float * Adjugate (int n, float array[n][n]);
float * Invertible (int n, float array[n][n]);
//MAIN #TODO
int * main(int argc, char *argv[]) {
int l;
int c;
int o;
float v;
printf("Insert the array order: ");
scanf("%d\n",&o);
static float array[100][100];
for(l=0;l<o;l++){
for(c=0;c<o;c++){
printf("\nInsert Cell value[%i][%i]: ",&l,&c);
scanf("%d",&v);
}
printf("\n");
}
array = Invertible (o,array[100][100]);
int op = 0
for(l=o;o>0;o--){
op=op+(l*l);
}
printf("\nOperation numbers=%d |",&op);
printf("\narray Invertible :\n |");
for(l=0;l<o;l++){
for(c=0;c<o;c++){
printf("%d |",&array[l][c]);
}
printf("\n");
}
return 0;
}
/*
|-------------------|
| FUNCTIONS |
|-------------------|
*/
//LAPLACE
float detLaplace(int n, float a[n][n]){
if(n == 1){
// array 1x1
return a[0][0];
}
else{
float det = 0;
int i, row, col, j_aux, i_aux;
//Select first line to calculate the cofactors
for(i = 0; i < n; i++){
//ignore the zeros (zero time anything equal zero)
if (a[0][i] != 0) {
float aux[n - 1][n - 1];
i_aux = 0;
j_aux = 0;
//Generate the array to calculate the cofactors
for(row = 1; row < n; row++){
for(col = 0; col < n; col++){
if(col != i){
aux[i_aux][j_aux] = a[row][col];
j_aux++;
}
}
i_aux++;
j_aux = 0;
}
float factor = (i % 2 == 0)? a[0][i] : -a[0][i];
det = det + factor * detLaplace(n - 1, aux);
}
}
return det;
}
}
//Generate cofactor array
float * matcafactor(int n, float a[n][n]){
static float matCof[n][n];
float aux[n - 1][n - 1];
float det = 0;
int i, row, col, j_aux, i_aux;
for(i = 0; i < n; i++){
i_aux = 0;
j_aux = 0;
//Generate the array to calculate the cofactors
for(row = 1; row < n; row++){
for(col = 0; col < n; col++){
if(col != i){
aux[i_aux][j_aux] = a[row][col];
j_aux++;
}
}
i_aux++;
j_aux = 0;
}
float factor = (i % 2 == 0)? a[0][i] : -a[0][i];
matCof[i][n] = factor * detLaplace(n - 1, aux);
}
//Return the cofactor array https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSWQrcWYyqWK9wUGoUS9bnaGn5iCmj6CD9016BF0jopfcg4Xsme
return matCof;
}
//Transpose the array
float * Transpose(int n, float array[n][n]){
int Row=0;
int Column=0;
static float[n][n] matTramp;
for(Row< D,Row++){
for(Column< D,Column++){
matTramp[Column,Row] = array[Row,Column];
}
}
//Return the Transpose the array
return matTramp;
}
float * Adjugate (int n, float array[n][n]){
static float matAux[n][n];
matAux = matcafactor(n,array[n][n]);
matAux = Transpose(n,matAux[n][n]);
//return the Transpose cafactors array
return matAux;
}
float * Invertible (int n, float array[n][n]){
static float matAux[n][n];
float detPrincipal=0;
int i;
int j;
//Get the determinant of the main array detPrincipal= mainDertminant
detPrincipal = detLaplace(n, array[n][n]);
matAux = Adjugate (n,array[n][n]);
for(i = 0, i<n,i++){
for(j = 0, i<n,i++){
matAux[n][n] = matAux[n][n]*(1/detPrincipal);
}
}
return matAux;
}
[100][100]after the identifier for the array - what you are doing with this line is indexing the 100th column of the 100th row of array, thus you are passing an argument of typefloatto Invertible, who expectsfloat [][]as the second argument - the line should look like this:array = Invertible (o,array);return marAux;are returningfloat (*)[n], notfloat *. There is a difference, and being unfamiliar with that is related to the root problem you already identified ("don't know the language"). This can't possibly compile regardless, as the misplaced{after what should be thematcafactorprototype. Also, you can't have static variable length arrays in C, so that won't work either. In short, the problem are numerous, and there is no quick fix to this.array(of size 100x100) to functions that are told, for example, that the size is 4 and the array is supposed to bearray[n][n](where I hypothesize thatn == 4). You're brave if you actually type 10,000 numbers for a 100x100 array. Also, you read the values intov(after misprinting by including the&in&land&cin the call toprintf()), and never set the array. As was said, you have major surgery to do to create a compilable program.[Column,Row]==>[Column][Row]