Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a recursive function called Fibonacci(n) that returns nth number in Fibona

ID: 656460 • Letter: W

Question

Write a recursive function called Fibonacci(n) that returns nth number in Fibonacci series. In fibonnaci series each number after the first number is the summation of last two numbers. For example following sequence is Fibonacci series:

1,1,2,3,5,8,13,21,34... That means Fibonacci(6) should be 8 because the 6th Fibonacci number is 8 in that series

[hint: You must have a termination condition and also, express the Fibonacci number in recursive equation form based on the above definition]

simple c++ & can you make it short for me to remember for exams!

Explanation / Answer

#include<iostream>
using namespace std;
//Recursive Function starts here.
int Fibonacci(int n){
   if(n==1 || n==2)
   return 1;
   return Fibonacci(n-1)+Fibonacci(n-2);
}

//Recursive Function ends here.
int main(){
   cout <<"6th Fibonacci number is " << Fibonacci(6) << endl;
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote