Reputation: 3
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;
}
Upvotes: 0
Views: 106
Reputation: 8614
You have many errors in your program.
int * main(int argc, char *argv[])
should be
int main(int argc, char *argv[])
Main should return integer not pointer to integer.
printf("\nInsert Cell value[%i][%i]: ",&l,&c);
should be printf("\nInsert Cell value[%i][%i]: ",l,c);
l
and c
are int
's. Therefore the printf should use the value directly.
scanf("%d",&v);
should be scanf("%f",&v);
v
is a float. For float's you should use %f
for printf
and scanf`
array = Invertible (o,array[100][100]);
to Invertible (o,array);
You have two issues here. Firstly, in the assignment you are using array[100]100]
. Secondly, You are assigning the result back to array
.
The type of Invertible
is float * Invertible (int n, float array[n][n]);
You cannot assign a float
pointer to an array.
int op = 0
--> Missing semicolon.
printf("\nOperation numbers=%d |",&op);
and printf("%d |",&array[l][c]);
Remove the & and use %f for the array.
static float matCof[n][n];
-> You need to decide the size of this array in advance.
There are many more errors, but you can get going with these.
You should compile your code with the -Wall
option to get these errors.
Upvotes: 1