Question

In mathematics, the Fibonacci numbers are the series of number that exhibit the following pattern: 0,1,1,2,3,5,8,13,21,34,55,89,144,.......

  1. In mathematics, the Fibonacci numbers are the series of number that exhibit the following pattern:

0,1,1,2,3,5,8,13,21,34,55,89,144,....

In mathematical notation the sequence Fn of Fibonacci number is defined by the following recurrence relation:

Fn=Fn-1+Fn-2

With the initial values of F0=0 and F1=1. Thus, the next number in the series is the sum of the previous two numbers. Write a program that asks the user for a positive integer N and generate the Nth Fibonacci number. Your main function should handle user input and pass that data to a function called Fib that takes n integer value N as input and a reference parameter that is assigned the Nth Fibonacci number.

please write in C++

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

#include <iostream>

using namespace std;

//fib is the recursive method that calculates nth fibonacci number

int fib(int n) {

   if (n <= 1)

      return n;

   return fib(n-1) + fib(n-2);

}

int main(){

    int n = 0;

    //Getting n from user

    cout<<"Enter n: ";

    cin>>n;

    //printing out the results

    cout<<"Fib("<<n<<") = "<<fib(n);

    return 0;

}

Output:

Add a comment
Know the answer?
Add Answer to:
In mathematics, the Fibonacci numbers are the series of number that exhibit the following pattern: 0,1,1,2,3,5,8,13,21,34,55,89,144,.......
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
  • PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a...

    PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a function yesOrNo which has no parameters. When called, it gets input from the user until the user types either 'yes' or 'no', at which point the function should return True if the user typed 'yes' and False if the user typed 'no'. Any other entries by the user are ignored and another value must be input. For example: Test Input Result print(yesOrNo()) hello blank...

  • Write a program in MIPs Assembly Language to compute nth number of a fibonacci number sequence....

    Write a program in MIPs Assembly Language to compute nth number of a fibonacci number sequence. Your program should prompt for an integer input n from the user. The program should call a recursive function to compute the nth fibonacci number. Your program must follow programming convention. You should submit program and screenshot of output in a single word/pdf file. You should use following recursive definition of fibonacci function: fib(0) = 0 fib(1) = 1 fib(n) = fib(n-1) +fib(n-2)

  • Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a...

    Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a one-dimensional array with the first 30 Fibonacci numbers using a calculation to generate the numbers. Note: The first two Fibonacci numbers 0 and 1 should be generated explicitly as in -long[] series = new long[limit]; //create first 2 series elements series[0] = 0; series[1] = 1; -But, it is not permissible to fill the array explicitly with the Fibonacci series’ after the first two...

  • Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5,...

    Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers before it. The 2 is found by adding the two numbers before it (1+1) The 3 is found by adding the two numbers before it (1+2), And the 5 is (2+3), and so on!         Example: the next number in the sequence above is 21+34 = 55 Source:...

  • in C++ 6. (20)The Fibonacci sequence is the series of integers 0, 1, 1,2, 3, 5,...

    in C++ 6. (20)The Fibonacci sequence is the series of integers 0, 1, 1,2, 3, 5, 8, 13, 21, 34, 55, 89.. 1 See the pattern? Each element in the series is the sum of the preceding two items. There is a recursive formula for calculating the nth number of the sequence (the oth number if Fib(0)-0): 8 Fib(N)-/N, if N 0 or 1 ifN> 1 Fib(N-2) Fib(N-1), a. b. c. Write a recursive version of the function Fibonacci. Write...

  • Using R code only 4. The Fibonacci numbers are the sequence of numbers defined by the...

    Using R code only 4. The Fibonacci numbers are the sequence of numbers defined by the linear recurrence equation Fn F-1 F-2 where F F2 1 and by convention Fo 0. For example, the first 8 Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13, 21. (a) For a given n, compute the nth Fibonnaci number using a for loop (b) For a given n, compute the nth Fibonnaci number using a while loop Print the 15th Fibonacci number...

  • 2. The Fibonacci numbers are defined by the sequence: f = 1 f2 = 1 fo=fni...

    2. The Fibonacci numbers are defined by the sequence: f = 1 f2 = 1 fo=fni + 2 Implement a program that prompts the user for an integer, n, and prints all the Fibonacci numbers, up to the nth Fibonacci number. Use n=10. Show a sample output with the expected results. Output: Enter a number: 100 number Fib 89

  • The Fibonacci sequence is named after an Italian mathematician: Leonardo Bonacci (c. 1170-c. 1250...

    The Fibonacci sequence is named after an Italian mathematician: Leonardo Bonacci (c. 1170-c. 1250)-known as Fibonacci, and also Leonardo of Pisa, Leonardo Pisano Bigollo, and as Leonardo Fibonacci. His 1202 book Liber Abaci introduced the sequence to Western European mathematics, although the sequence had been described earlier in Indian mathematics. In mathematical terms, the sequence F of Fibonacci numbers is defined by the recurrence relation FF1F-2 with seed values F1, F21or F1-0, F2-1 The Liber Abaci began the sequence with...

  • • Fibonacci numbers, denoted as Fn, form a sequence, called the Fibonacci sequence, such that each...

    • Fibonacci numbers, denoted as Fn, form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. • Fn = Fn-1 + Fn-2 (n > 1) • Fo = 0 and F1 = 1 • Submit the R script to write the first 100 numbers of Fibonacci sequence, i.e., F, to F99, to a file named as Fibonacci_100.txt and put in the folder in path /user/R/output/. •...

  • 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...

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