Finished 11 section exercises
This commit is contained in:
parent
2cc0db7791
commit
69ca802606
1 changed files with 27 additions and 0 deletions
27
c_modern_approach/Pointers/exercises/e_8.c
Normal file
27
c_modern_approach/Pointers/exercises/e_8.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#define MAX_RANDOM_VALUE 1000
|
||||
#define ARRAY_SIZE 10
|
||||
|
||||
int *find_largest(int a[], int n) {
|
||||
int highest_number_index = 0;
|
||||
for (int i = 0; i < ARRAY_SIZE; i++) {
|
||||
if (a[i] > highest_number_index) {
|
||||
highest_number_index = i;
|
||||
}
|
||||
}
|
||||
return &a[highest_number_index];
|
||||
}
|
||||
|
||||
int main() {
|
||||
int random_numbers_array[ARRAY_SIZE];
|
||||
int *highest_index;
|
||||
srand(time(NULL));
|
||||
for (int i = 0; i < ARRAY_SIZE; i++) {
|
||||
random_numbers_array[i] = rand() % MAX_RANDOM_VALUE + 1;
|
||||
}
|
||||
highest_index = find_largest(random_numbers_array, ARRAY_SIZE);
|
||||
printf("HI: %p\n", highest_index);
|
||||
printf("VALUE: %d", *highest_index);
|
||||
}
|
Loading…
Reference in a new issue