Skip to content

Commit cfb5925

Browse files
authored
04 recursive_max in C (egonSchiele#278)
1 parent 11a2de7 commit cfb5925

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

04_quicksort/c/04_recursive_max.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdio.h>
2+
3+
int max(int *arr, int index, int size){
4+
//base case
5+
if (index == size - 1)
6+
return arr[index];
7+
8+
int sub_max = max(arr, index + 1, size);
9+
10+
return (arr[index] > sub_max) ? arr[index] : sub_max;
11+
}
12+
13+
int main(void){
14+
int arr[] = {2,3,6,5,5};
15+
// the C way of calculating the size of an array
16+
int size = sizeof(arr) / sizeof(arr[0]);
17+
printf("%d", max(arr, 0, size));
18+
return 0;
19+
}

0 commit comments

Comments
 (0)