열렬히.뛰기

ft_rrange

école 42 > exam02 > exam02 : part3 > ft_rrange

공략법

  • 배열의 사이즈 = abs(end - start) + 1
  • start ~ end 까지 배열에 넣어줘야 함.
    • end부터 배열에 넣어줘야 함!
    • 이때, end ≤ start 면 end를 늘려가면서 넣어주기
    • 한편, end ≥ start 면 end를 줄여가면서 넣어주기

문제

Assignment name  : ft_rrange
Expected files   : ft_rrange.c
Allowed functions: malloc
--------------------------------------------------------------------------------

Write the following function:

int     *ft_rrange(int start, int end);

It must allocate (with malloc()) an array of integers, fill it with consecutive
values that begin at end and end at start (Including start and end !), then
return a pointer to the first value of the array.

Examples:

- With (1, 3) you will return an array containing 3, 2 and 1
- With (-1, 2) you will return an array containing 2, 1, 0 and -1.
- With (0, 0) you will return an array containing 0.
- With (0, -3) you will return an array containing -3, -2, -1 and 0.