diff --git a/CalculatorFunctions/fibonacci.c b/CalculatorFunctions/fibonacci.c index 30d03df..9768838 100644 --- a/CalculatorFunctions/fibonacci.c +++ b/CalculatorFunctions/fibonacci.c @@ -1 +1,21 @@ /* Make a function that calculates the first n fibonacci numbers. Bonus points if it is recursive! */ +#include +void printFibonacci(int n); +int main(){ + int n; + printf("Enter the number of elements: "); + scanf("%d",&n); + printf("Fibonacci Series: "); + printf("%d %d ",0,1); + printFibonacci(n-2); + return 0; +} +void printFibonacci(int n){ + static int n1=0,n2=1,n3; + if(n>0){ + n3 = n1 + n2; + n1 = n2; + n2 = n3; + printf("%d ",n3); + printFibonacci(n-1); + }