blob: de8c414d3f127fca484d5fcd25f328cca46c141b (
plain)
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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_range.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: exam <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/12 18:00:18 by exam #+# #+# */
/* Updated: 2019/07/12 18:32:44 by exam ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int *ft_range(int start, int end)
{
int *range;
int i;
range = (int*)malloc(sizeof(int) *
(end - start < 0 ? start - end : end - start + 1));
if (range == NULL)
return (NULL);
i = 0;
if (start < end)
while (start <= end)
{
range[i] = start;
start++;
i++;
}
else
while (start >= end)
{
range[i] = start;
start--;
i++;
}
return (range);
}
|