Programming with C

⌘K
  1. Home
  2. Docs
  3. Programming with C
  4. Functions and Pointers
  5. Recursion
  6. Finding Fibonacci series using Recursion

Finding Fibonacci series using Recursion

Finding Fibonacci series using Recursion

#include<stdio.h>
int fibonacci(int x);
int main()
{
	int i,n;
	printf("Enter number of terms");
	scanf("%d",&n);
	for(i = 0;i<n;i++)
	{
		printf("%d\t",fibonacci(i));
	}
}
int fibonacci(int x)
{
	if(x<2)
	{
		return x;
	}
	else
	{
		return fibonacci(x-1) + fibonacci(x-2);
	}
}

Output

Enter number of terms 5
0       1       1       2       3

Views: 0

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments