aboutsummaryrefslogtreecommitdiff
path: root/c05/ex04/ft_fibonacci.c
blob: 66ff9b14e9468a9b0e207e65f1d4687100502200 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_fibonacci.c                                     :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <charles.cabergs@gmail.com>       +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2019/07/06 19:34:02 by cacharle          #+#    #+#             */
/*   Updated: 2019/07/06 19:37:37 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

int ft_fibonacci(int index)
{
	if (index < 0)
		return (-1);
	if (index == 0)
		return (0);
	if (index == 1 || index == 2)
		return (1);
	return ft_fibonacci(index - 1) + ft_fibonacci(index - 2);
}