This program has 3 functions that work on a K-dimensional array. Each function takes input parameters of the K-dimensional array and the bounds of that array's dimensions. The behaviour of the functions is as follows:
- This function initializes each element in the input array to 0.
- This function sets 10% of all elements of the array to 1 uniformly.
- This function randomly chooses 5% of the input array and prints out its co-ordinates and the value of the element at this position.
The elements in arrays are usually accessed through the use of loops. As the input array is not static in this program, that is the array does not have the same defined dimensions on every input, it is computationally expensive to continually loop through the array accodring to the number of dimensions it has. However, arrays, regardless of dimension, are stored contiguously in memory. In the C programming language, this is stored using a row major order. By transforming the K co-ordinates of a K-dimensional array into a 1-dimensional co-ordinate system, any element can be accessed using a pointer, eliminating the need for multiple loops.
In a terminal:
# Clone the Repo
git clone https://github.com/data-intensive-computing-4020/Lab1.git
# Compile main.c
gcc -o main main.c
# Run the executable
./mainThe description and explanation of our code can be found in the documentation folder. Both the .tex and .pdf are included.