Table of Contents
show
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