Question

Fibonacci num Fn are defined as follow. F0 is 1, F1 is 1, and Fi+2 =...

Fibonacci num Fn are defined as follow. F0 is 1, F1 is 1, and Fi+2 = Fi + Fi+1, where i = 0, 1, 2, . . . . In other words, each number is the sum of the previous two numbers.

Write a recursive function definition in C++ that has one parameter n of type int and that returns the n-th Fibonacci number. You can call this function inside the main function to print the Fibonacci numbers.

Sample Input and Output:

Display Fibonacci numbers 0-N.
Enter a limit: 5
11235
Y/y to continue, anything else quits: y Display Fibonacci numbers 0-N.

Enter a limit: 15
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 Y/y to continue, anything else quits: n

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
using namespace std;

int fiboSeries(int N)
{
if((N==1)||(N==0))
{
return N;
}
else
{
return (fiboSeries(N-1)+fiboSeries(N-2));
}
}

int main()
{
int N ;
int i;
char ch;

while(1)
{

i=1;
cout<<"\n\nDisplay Fibonacci numbers 0-N. \n\n";
cout<<"Enter a limit : ";
cin>>N;

cout<<endl<<endl;
while(i<=N)
{
cout<<fiboSeries(i)<<" ";
i++;
}

cout<<"\n\n y to continue, anything else to quits : ";
cin>>ch;

if(ch!='y')
{
break;
}


}
cout<<endl<<endl;
system("pause");
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Fibonacci num Fn are defined as follow. F0 is 1, F1 is 1, and Fi+2 =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 3. The sequence (Fn) of Fibonacci numbers is defined by the recursive relation Fn+2 Fn+1+ F...

    3. The sequence (Fn) of Fibonacci numbers is defined by the recursive relation Fn+2 Fn+1+ F for all n E N and with Fi = F2= 1. to find a recursive relation for the sequence of ratios (a) Use the recursive relation for (F) Fn+ Fn an Hint: Divide by Fn+1 N (b) Show by induction that an 1 for all n (c) Given that the limit l = lim,0 an exists (so you do not need to prove that...

  • Let f0, f1, f2, . . . be the Fibonacci sequence defined as f0 = 0,...

    Let f0, f1, f2, . . . be the Fibonacci sequence defined as f0 = 0, f1 = 1, and for every k > 1, fk = fk-1 + fk-2. Use induction to prove that for every n ? 0, fn ? 2n-1 . Base case should start at f0 and f1. For the inductive case of fk+1 , you’ll need to use the inductive hypothesis for both k and k ? 1.

  • C++ Fibonacci Complete ComputeFibonacci() to return FN, where F0 is 0, F1 is 1, F2 is...

    C++ Fibonacci Complete ComputeFibonacci() to return FN, where F0 is 0, F1 is 1, F2 is 1, F3 is 2, F4 is 3, and continuing: FN is FN-1 + FN-2. Hint: Base cases are N == 0 and N == 1. #include <iostream> using namespace std; int ComputeFibonacci(int N) { cout << "FIXME: Complete this function." << endl; cout << "Currently just returns 0." << endl; return 0; } int main() { int N = 4; // F_N, starts at...

  • The Fibonacci numbers are defined as follows, f1=1, f2=1 and fn+2=fn+fn+1 whenever n>= 1. (a) Characterize...

    The Fibonacci numbers are defined as follows, f1=1, f2=1 and fn+2=fn+fn+1 whenever n>= 1. (a) Characterize the set of integers n for which fn is even and prove your answer using induction (b) Please do b as well. The Fibonacci numbers are defined as follows: fi -1, f21, and fn+2 nfn+1 whenever n 21. (a) Characterize the set of integers n for which fn is even and prove your answer using induction. (b) Use induction to prove that Σ. 1...

  • 20. The Fibonacci numbers start with Fo 0, F1 1 , 1, F2 etc: 0,1,1,2,3,5,8,13,21,34,55,89, 144, 233,377,... Show tha...

    20. The Fibonacci numbers start with Fo 0, F1 1 , 1, F2 etc: 0,1,1,2,3,5,8,13,21,34,55,89, 144, 233,377,... Show that if m is a factor of n, then Fm is a factor of Fn. For example, F7 13 is a factor of F14 377. 20. The Fibonacci numbers start with Fo 0, F1 1 , 1, F2 etc: 0,1,1,2,3,5,8,13,21,34,55,89, 144, 233,377,... Show that if m is a factor of n, then Fm is a factor of Fn. For example, F7 13...

  • (5) Fibonacci sequences in groups. The Fibonacci numbers Fn are defined recursively by Fo 0, F1...

    (5) Fibonacci sequences in groups. The Fibonacci numbers Fn are defined recursively by Fo 0, F1 -1, and Fn - Fn-1+Fn-2 forn 2 2. The definition of this sequence only depends on a binary operation. Since every group comes with a binary operation, we can define Fibonacci- type sequences in any group. Let G be a group, and define the sequence {fn in G as follows: Let ao, a1 be elements of G, and define fo-ao, fi-a1, and fn-an-1an-2 forn...

  • 2. The Fibonacci numbers are defined recursively as follows: fo = 0, fi = 1 and...

    2. The Fibonacci numbers are defined recursively as follows: fo = 0, fi = 1 and fn fn-l fn-2 for all n > 2. Prove that for all non-negative integers n: fnfn+2= (fn+1)2 - (-1)" 2. The Fibonacci numbers are defined recursively as follows: fo = 0, fi = 1 and fn fn-l fn-2 for all n > 2. Prove that for all non-negative integers n: fnfn+2= (fn+1)2 - (-1)"

  • The Fibonnaci sequence is a recursive sequence defined as: f0 = 1, f1 = 1, and...

    The Fibonnaci sequence is a recursive sequence defined as: f0 = 1, f1 = 1, and fn = fn−1 + fn−2 for n > 1 So the first few terms are 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, . . .. Write a function/procedure/algorithm that computes the sum of all even-valued Fibonnaci terms less than or equal to some positive integer k. For example the sum of all even-valued Fibonnaci terms less than or equal to 40...

  • I need help with this code. Im using C++ coding. Non Recursive (iterative) Fibonacci Write a...

    I need help with this code. Im using C++ coding. Non Recursive (iterative) Fibonacci Write a program that uses a for loop to calculate a Fibonacci sequence (NOT RECURSIVE!!!) up to a given position, starting with position 0. This function defines a Fibonacci sequence: If the number is 0, the function returns a 0 If the number is 1, the function returns a 1 If the number is higher than 1, it returns the sum of the previous two numbers...

  • Recall from class that the Fibonacci numbers are defined as follows: fo = 0,fi-1 and for all n fn...

    Recall from class that the Fibonacci numbers are defined as follows: fo = 0,fi-1 and for all n fn-n-1+fn-2- 2, (a) Let nEN,n 24. Prove that when we divide In by f-1, the quotient is 1 and the remainder is fn-2 (b) Prove by induction/recursion that the Euclidean Algorithm takes n-2 iterations to calculate gcd(fn,fn-1) for n 2 3. Check your answer for Question 1 against this. Recall from class that the Fibonacci numbers are defined as follows: fo =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT