inital commit. Set up all the exercises
This commit is contained in:
Binary file not shown.
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user