-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_minmax.c
54 lines (49 loc) · 1.41 KB
/
ft_minmax.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
49
50
51
52
53
54
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_minmax.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rvandepu <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 08:12:34 by rvandepu #+# #+# */
/* Updated: 2024/05/22 10:08:49 by rvandepu ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdarg.h>
#include <limits.h>
int ft_min(unsigned int n, ...)
{
va_list args;
int min;
int i;
if (n-- < 1)
return (INT_MAX);
va_start(args, n);
min = va_arg(args, int);
while (n--)
{
i = va_arg(args, int);
if (i < min)
min = i;
}
va_end(args);
return (min);
}
int ft_max(unsigned int n, ...)
{
va_list args;
int max;
int i;
if (n-- < 1)
return (INT_MIN);
va_start(args, n);
max = va_arg(args, int);
while (n--)
{
i = va_arg(args, int);
if (i > max)
max = i;
}
va_end(args);
return (max);
}