Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Fibonacci.c' #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions CalculatorFunctions/fibonacci.c
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
/* Make a function that calculates the first n fibonacci numbers. Bonus points if it is recursive! */
#include<stdio.h>
int fibonacci(int n)
{ //recursive function for generating fibonacci series
if(n == 0)
{ //base case
return 0;
}
else if(n == 1)
{ //for second term
return 1;
}
else
{
return (fibonacci(n-1) + fibonacci(n-2)); //uses previous values to generate the next value
}
}

int main()
{ //main function to run the code
int n,i;
printf("Enter the number of terms: ");
scanf("%d",&n); //taking number of terms as user input
printf("Fibonacci of %d: " , n);
for(i=0;i<n;i++)
{
printf("%d ",fibonacci(i));
}
}