I am trying to make a 2D dynamic array that calculates the derteminant of 4 or 9 numbers.
While using pointers and a dynamic array worked flawlessly in a 1D array, I can't wrap my head around what I have to do to make it owrk in 2D. So far, the program compiles properly and receives input. However, it does not print anything. I even tried printing a single cell content. Nothing.
Here is the code:
#include <stdio.h>
#include <stdlib.h>
int size; int i; int j; int **arDet; int a; int b; int c; int d; int e; int f; int g; int h;
int input()
{
do
{
scanf("%d", &size);
}while(size > 3 || size < 2);
arDet = (int**)malloc(sizeof(int)*size);
for(i = 0 ; i < size; i++)
{
for(j = 0 ; j < size; j++)
{
scanf("%d", &arDet[i][j]);
}
}
}
int main()
{
input();
if(size == 2)
{
printf("%d\n", arDet[0][0]*arDet[1][1] - arDet[0][1]*arDet[1][0]);
return 0;
}else if(size == 3)
{
// printf("%d", arDet[0]*(arDet[4]*arDet[8] - arDet[7]*arDet[5]) - arDet[1]*(arDet[3]*arDet[8] - arDet[5]*arDet[6]) + arDet[2]*(arDet[3]*arDet[7] - arDet[6]*arDet[4]));
return 0;
}else
{
return -1;
}
}