From 102341d7ae8793c29d44fa416d3b5b797d1eca3e Mon Sep 17 00:00:00 2001 From: Clay Smith Date: Tue, 1 Aug 2023 01:09:09 -0500 Subject: First commit --- nesting_tutorial.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 nesting_tutorial.c (limited to 'nesting_tutorial.c') diff --git a/nesting_tutorial.c b/nesting_tutorial.c new file mode 100644 index 0000000..2e22967 --- /dev/null +++ b/nesting_tutorial.c @@ -0,0 +1,58 @@ +#include +#include +#include + +#define WIDTH 100 +#define LENGTH 100 + +struct max_min { + long long int max; + long long int min; +}; + + +long long int return_max(long long int array[][LENGTH], int length, int width) +{ + long long int max = array[0][0]; + for (int i = 0; i < WIDTH; ++i) { + for (int j = 0; j < LENGTH; ++j) { + if (array[i][j] > max) { + max = array[i][j]; + } + } + } + return max; +} + +struct max_min return_min(long long int array[][LENGTH], int length, int width) +{ + struct max_min func_struct; + func_struct.min = array[0][0]; + for (int i = 0; i < WIDTH; ++i) { + for (int j = 0; j < LENGTH; ++j) { + if (array[i][j] < func_struct.min) { + func_struct.min = array[i][j]; + } + } + } + func_struct.max = return_max(array, length, width); + return func_struct; +} + +int main(void) +{ + srand(time(NULL)); + long long int two_d_array[WIDTH][LENGTH]; + + for (int i = 0; i < WIDTH; ++i) { + for (int j = 0; j < LENGTH; ++j) { + two_d_array[i][j] = rand() % 100000; + } + } + struct max_min newStruct = return_min(two_d_array, LENGTH, WIDTH); + printf("%lld\t%lld\n", newStruct.max, newStruct.min); + + // printf("%lld, %lld, %lld\n", two_d_array[rand() % (WIDTH - 1)][0],two_d_array[rand() % (WIDTH - 1)][0],two_d_array[rand() % (WIDTH - 1)][0] ); + + return 0; +} -- cgit v1.2.1