Respuesta :

Answer:

Here is code in C++.

// include header

#include<bits/stdc++.h>

using namespace std;

// function to calculate the nth Fibonacci term

int nth_fib(int num)

{   // base case for the recursive function

if (num <= 1)

 return num;

 // calculate the Fibonacci term by adding last two term of the sequence

return nth_fib(num-1) + nth_fib(num-2);

}

int main ()

{

   // variable to read term

int num;

cout<<"Please Enter the number: ";

cin>>num;

// calling the function to return the nth term of Fibonacci sequence

cout <<"The "<<num<<"th Fibonacci term is: "<<nth_fib(num);

 

return 0;

}

Explanation:

Declare a variable "num" to read the term. Call the function nth_fib() with parameter "num"; .In the nth_fib(),if num is less or equal to 1 then it will return(base case of recursive function).Otherwise it will calculate the Fibonacci term by adding the previous two terms. When it reaches to base condition, The function will return the nth term of sequence.

Output:

Please Enter the number:6

The 6th Fibonacci term is: 8

ACCESS MORE