-
Notifications
You must be signed in to change notification settings - Fork 0
/
questao4.c
48 lines (35 loc) · 969 Bytes
/
questao4.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "common/common.h"
void _maxMin(int array[], int first, int size, int *max, int *min){
if(size - first <= 1){
if(*max < array[size - 1]) *max = array[size - 1];
if(*min > array[size - 1]) *min = array[size - 1];
return;
}
int p = (first + size)/2;
_maxMin(array, first, p, max, min);
_maxMin(array, p, size, max, min);
}
void maxMin(int array[], int size, int *max, int *min){
*max = array[0];
*min = array[0];
_maxMin(array, 0, size, max, min);
}
int main(int argc, char *argv[]){
int min, max;
int size = randIntB2in(5, 15);
int list[size];
print("Lista: ");
for(int i = 0; i < size; i++){
list[i] = randInt(100);
print(list[i]);
if(i + 1 < size) print(", ");
else print(";");
}
printNewLine();
maxMin(list, size, &max, &min);
print("Máximo: ");
printLn(max);
print("Minimo: ");
printLn(min);
return 0;
}