Mostly the same code as before but I'm trying to use functions and calling by reference to input the matrices. But I'm still getting a similar error as before, and I can't see where I'm going wrong. Thanks.
12 cannot convert `float (*)[2][2]' to `float* (*)[2]' for argument `1' to `void getmatrixA(float* (*)[2])'
13 cannot convert `float (*)[2]' to `float**' for argument `1' to `void getmatrixB(float**)'
Code:
#include <stdio.h>
void getmatrixA(float *A[2][2]);
void getmatrixB(float *B[2]);
float determinant(float a[2][2]);
main ()
{
int col, row, x=2, y=2;
float A[2][2], B[2], Ak[2][2], detA;
getmatrixA(&A);
getmatrixB(&B);
detA = determinant(A);
printf("Determinant of A: %f\n", detA);
for(row=0 ; row<y; row++)
{
for(col=0 ; col<x ; col++)
{
if(col=0)
Ak[row][col]=B[row];
else
Ak[row][col]=A[row][col];
}
}
printf("Ak:\n");
for(row=0 ; row<y; row++)
{
for(col=0 ; col<x ; col++)
printf("[%f]", Ak[row][col]);
putchar('\n');
}
}
void getmatrixA(float *A[2][2])
{
int col, row;
printf("Enter Matrix A: ");
for(row=0 ; row<2; row++)
{
for(col=0 ; col<2 ; col++)
scanf("%f", &A[row][col]);
}
printf("You entered:\n");
for(row=0 ; row<2; row++)
{
for(col=0 ; col<2 ; col++)
printf("[%f]", A[row][col]);
putchar('\n');
}
}
void getmatrixB(float *B[2])
{
int col, row;
printf("Enter Matrix B: ");
for(row=0 ; row<2; row++)
scanf("%f", &B[row]);
printf("You entered:\n");
for(row=0 ; row<2; row++)
printf("[%f]\n", B[row]);
}
/* Calculate determinant of matrix A */
float determinant(float a[2][2])
{
float det;
det = a[0][0]*a[1][1] - a[0][1]*a[1][0];
return det;
}