summaryrefslogtreecommitdiff
path: root/nesting_tutorial.c
diff options
context:
space:
mode:
authorClay Smith <claysmith158@gmail.com>2023-08-01 01:09:09 -0500
committerClay Smith <claysmith158@gmail.com>2023-08-01 01:09:09 -0500
commit102341d7ae8793c29d44fa416d3b5b797d1eca3e (patch)
tree6df9a5d5ef978dc6809a7d71d50de6e359dae2e7 /nesting_tutorial.c
First commitHEADmain
Diffstat (limited to 'nesting_tutorial.c')
-rw-r--r--nesting_tutorial.c58
1 files changed, 58 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#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;
+}