Answer to Question #265548 in C++ for Usama

Question #265548

Problem Statement 2 The Fibonacci series 0, 1, 1, 2, 3, 5, 8, 13, 21, … Begins with the terms 0 and 1 and has the property that each succeeding term is the sum of the two preceding terms. Write a recursive function that generates N series numbers. Where N is the integer inputted by the user at runtime.


1
Expert's answer
2021-11-18T15:15:22-0500
#include<iostream>
using namespace std;
 
int Fibonacci (int number)
{
  if(number == 0){
		return 0;
	}
	if(number == 1 || number == 2){
			return 1;
		}
	return Fibonacci(number-2) + Fibonacci(number-1);
}
int main ()
{
	cout<<"Enter N: "<<endl;
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
    	cout << Fibonacci(i)<<" ";
	}
    
    getchar();
    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