mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-25 06:49:36 +03:00
56b72da9fb
...algorithms to the `math` folder. Co-authored-by: David Leal <halfpacho@gmail.com>
23 lines
384 B
C
23 lines
384 B
C
#include <stdio.h>
|
|
|
|
// Fibonnacci function
|
|
int fib(int number)
|
|
{
|
|
if (number == 1 || number == 2)
|
|
return 1;
|
|
else
|
|
return fib(number - 1) + fib(number - 2);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
int number;
|
|
|
|
// Asks for the number that is in n position in Fibonnacci sequence
|
|
printf("Number: ");
|
|
scanf("%d", &number);
|
|
|
|
printf("%d \n", fib(number));
|
|
|
|
return 0;
|
|
} |