Program to print the Fibonacci numbers using recursion.
#include<bits/stdc++.h>
using namespace std;
int fib(int x)
{
if (x <= 1)
return x;
return fib(x-1) + fib(x-2);
}
int main ()
{
int x ;
cout << "Enter value: \n";
cin>>x;
cout<<fib(x);
return 0;
}
Comments
Leave a comment