im trying to do lu decomposition using nxn matrix typed by scanf but having errors on using nxn matrix for gauss function i what to know the ways to use array by malloc on function. the way to use matrix[x][y] on gauss fucntion is the point
#include <stdio.h>
#include <stdlib.h>
#pragma warning(disable:4996)
void gauss(int n,double **matrix,double **L,double **U,double **ans);
int main(void)
{
int i, n;//
int x, y;//line x,row y
double **matrix; //define matrix[x][y]
double **L;
double **U;
double **ans;
printf("nxn matrix type n.\n");
scanf("%d", &n);
matrix = malloc(sizeof(float *) * n); // int* number x primary structure
if (matrix == NULL){ printf("malloc failed\n"); exit(1); }
for (i = 0; i<n; i++)
{
matrix[i] = malloc(sizeof(float) * n);
if (matrix[i] == NULL){ printf("malloc failed\n"); exit(1); }
} //build matrix[x][y(size of x)] structure
L = malloc(sizeof(float *) * n); // int* number x primary structure
if (L == NULL){ printf("malloc failed\n"); exit(1); }
for (i = 0; i<n; i++)
{
L[i] = malloc(sizeof(float) * n);
if (L[i] == NULL){ printf("malloc failed\n"); exit(1); }
} //build L[x][y(size of x)] structure
U = malloc(sizeof(float *) * n); // int* number x primary structure
if (U == NULL){ printf("malloc failed\n"); exit(1); }
for (i = 0; i<n; i++)
{
U[i] = malloc(sizeof(float) * n);
if (U[i] == NULL){ printf("malloc failed\n"); exit(1); }
} //build U[x][y(size of x)] structure
ans = malloc(sizeof(float *) * n); // int* number x primary structure
if (ans == NULL){ printf("malloc failed\n"); exit(1); }
for (i = 0; i<n; i++)
{
ans[i] = malloc(sizeof(float) * n);
if (ans[i] == NULL){ printf("malloc failed\n"); exit(1); }
} //build ans[x][y(size of x)] structure
printf("type the number of matrix \n");
for (x = 0; x < n; x++){
for (y = 0; y < n; y++){
printf("line %d x%d number : ", x + 1, y + 1);
scanf("%lf", &matrix[x][y]);
}
}
/*
for (x = 0; x < n; x++){
for (y = 0; y < n; y++){
printf("line %d x%d number : %.2lf \n", x + 1, y + 1,matrix[x][y]);
}
}
*/
gauss(n,matrix,L,U,ans);
/*
for (i = 0; i<n; i++)
{
free(matrix[i]);
}
free(matrix);//free matrix
for (i = 0; i<n; i++)
{
free(L[i]);
}
free(L);//free L
for (i = 0; i<n; i++)
{
free(U[i]);
}
free(U);//free U
*/
return 0;
}
void gauss(int n,double **matrix,double **L,double **U,double **ans){
int x,y;
for(x=0;x<=n;x++){
if(matrix[x][0]!=0){
for(y=0;y<=n;y++){
matrix[x][y]=matrix[x][y]/matrix[x][0];
L[x][0]=matrix[x][0];
}
}
}
}