#include <stdio.h>
#include <stdlib.h>
#include "matrix.h"

int ***build_matrix(int nx, int ny, int nz)
{
	int ***matrix = (int ***)malloc(nz * sizeof(int **));
	for (int z = 0; z < nz; z++)
	{
		matrix[z] = (int **)malloc(ny * sizeof(int *));
		for (int y = 0; y < ny; y++)
		{
			matrix[z][y] = (int *)malloc(nx * sizeof(int));
			for (int x = 0; x < nx; x++)
			{
				matrix[z][y][x] = (z + 1) * 100 + (y + 1) * 10 + x + 1;
			}
		}
	}
	return matrix;
}

void print_matrix(int ***matrix, int nx, int ny, int nz)
{
	for (int z = 0; z < nz; z++)
	{
		for (int y = 0; y < ny; y++)
		{
			for (int x = 0; x < nx; x++)
			{
				printf("%i ", matrix[z][y][x]);
			}
			printf("\n");
		}
	}
}

void free_matrix(int ***matrix, int ny, int nz)
{
	for (int z = 0; z < nz; z++)
	{
		for (int y = 0; y < ny; y++)
		{
			free(matrix[z][y]);
		}
		free(matrix[z]);
	}
	free(matrix);
}