inital commit. Set up all the exercises

This commit is contained in:
2026-03-22 11:58:10 +01:00
commit 4332bbab5f
46 changed files with 1143 additions and 0 deletions
Binary file not shown.
+35
View File
@@ -0,0 +1,35 @@
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include "matrix.h"
int main()
{
// First example
int nz=3;
int nx=3;
int ny=3;
int*** matrix = build_matrix(nx, ny, nz);
assert(matrix[0][0][0] == 111 && "matrix[0][0][0] must be 111 after assignment");
assert(matrix[2][2][2] == 333 && "matrix[2][2][2] must be 333 after assignment");
print_matrix(matrix, nx, ny, nz);
free_matrix(matrix, ny, nz);
nz=3;
nx=1;
ny=2;
// Second example
matrix = build_matrix(nx, ny, nz);
assert(matrix[0][0][0] == 111 && "matrix[0][0][0] must be 111 after assignment");
assert(matrix[2][1][0] == 321 && "matrix[2][1][0] must be 321 after assignment");
print_matrix(matrix, nx, ny, nz);
free_matrix(matrix, ny, nz);
}
+34
View File
@@ -0,0 +1,34 @@
#include<stdio.h>
#include<stdlib.h>
int main()
{
const int nx=3;
const int ny=2;
int** matrix;
matrix = (int**)malloc(ny*sizeof(int*));
for(int y=0; y<ny; y++)
{
matrix[y] = (int*)malloc(nx*sizeof(int));
for(int x=0; x<nx; x++)
{
matrix[y][x] = (y+1)*10 + x+1;
}
}
for(int y=0; y<ny; y++)
{
for(int x=0; x<nx; x++)
{
printf("%i ",matrix[y][x]);
}
printf("\n");
}
for(int y=0; y<ny; y++)
{
free(matrix[y]);
}
free(matrix);
}