Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a C++ recursive function for the Fibonacci Sequence. Here is the program written in a non-recursive way that will display the first 10 digits

Create a C++ recursive function for the Fibonacci Sequence.

Here is the program written in a non-recursive way that will display the first 10 digits of the Fibonacci Sequence.

It must do the same, but needs to be written recursively.

Problem Two:

Here codes for non-recursive Fibonacci sequence problem, use it to rewrite a recursive Fibonacci solution:

//Program: Fibonacci number

#include

using namespace std;

void FibonacciNum( int position);

int main()

{

cout << "The Fibonacci numbers upto position "

<< 10 << " are " ;

FibonacciNum(11);

cout<< endl;

return 0;

}

void FibonacciNum( int nthFibNum)

{

int current;

int counter;

int first,second;

if (nthFibNum == 1)

{ first =1;

current = first;

cout<< current<<" ";

}

else if (nthFibNum == 2)

{

second = 2;

current = second;

cout<< current<<" ";

}

else

{

counter = 3;

while (counter <= nthFibNum)

{

current = second + first;

cout<< current<<" ";

first = second;

second = current;

counter++;

}//end while

}//end else

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Office 365 For Beginners 2022 8 In 1

Authors: James Holler

1st Edition

B0B2WRC1RX, 979-8833565759

More Books

Students also viewed these Databases questions

Question

Write an elaborate note on marketing environment.

Answered: 1 week ago