Answer to Question #181193 in C++ for Kanav Garg

Question #181193

Program to print the Fibonacci numbers using recursion.


1
Expert's answer
2021-04-14T07:07:12-0400
#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;
}
 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS