hab 1 augabe fertig, bin zu dumm das auf windows zu kompilieren deswegen mal schauen
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "matrix.h"
|
||||
|
||||
int main()
|
||||
int ***build_matrix(int nx, int ny, int nz)
|
||||
{
|
||||
const int nx = 1;
|
||||
const int ny = 2;
|
||||
const int nz = 3;
|
||||
int ***matrix;
|
||||
|
||||
matrix = (int ***)malloc(nz * sizeof(int **));
|
||||
int ***matrix = (int ***)malloc(nz * sizeof(int **));
|
||||
for (int z = 0; z < nz; z++)
|
||||
{
|
||||
matrix[z] = (int **)malloc(ny * sizeof(int *));
|
||||
@@ -17,10 +13,15 @@ int main()
|
||||
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;
|
||||
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++)
|
||||
@@ -32,7 +33,10 @@ int main()
|
||||
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++)
|
||||
@@ -42,4 +46,4 @@ int main()
|
||||
free(matrix[z]);
|
||||
}
|
||||
free(matrix);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
int ***build_matrix(int nx, int ny, int nz);
|
||||
void print_matrix(int ***matrix, int nx, int ny, int nz);
|
||||
void free_matrix(int ***matrix, int ny, int nz);
|
||||
Reference in New Issue
Block a user