TheAlgorithms-C/misc/fibonacci.c

23 lines
384 B
C
Raw Normal View History

2017-07-04 23:18:46 +03:00
#include <stdio.h>
// Fibonnacci function
int fib(int number)
{
if (number == 1 || number == 2)
return 1;
else
return fib(number - 1) + fib(number - 2);
2017-07-04 23:18:46 +03:00
}
int main()
{
int number;
2017-07-04 23:18:46 +03:00
// Asks for the number that is in n position in Fibonnacci sequence
printf("Number: ");
scanf("%d", &number);
printf("%d \n", fib(number));
return 0;
2017-07-04 23:18:46 +03:00
}