41 lines
1.2 KiB
C
41 lines
1.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_fibonacci.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/06/13 11:34:54 by whaffman #+# #+# */
|
|
/* Updated: 2024/06/13 11:40:20 by whaffman ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include <stdio.h>
|
|
|
|
int ft_fibonacci(int index)
|
|
{
|
|
if (index < 0)
|
|
return (-1);
|
|
else if (index < 2)
|
|
return (index);
|
|
else
|
|
return (ft_fibonacci(index - 1) + ft_fibonacci(index - 2));
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
int main(void)
|
|
{
|
|
int i;
|
|
|
|
i = -3;
|
|
while (i < 10)
|
|
{
|
|
printf("fib(%d) = %d\n", i, ft_fibonacci(i));
|
|
i++;
|
|
}
|
|
return (0);
|
|
}
|
|
|
|
#endif
|