Question

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: https://www.mathsisfun.com/numbers/fibonacci-sequence.html

In this lab you will write a program that allows the user to enter a number. This number will represent the maximum position of the Fibonacci sequence that the user wants to print. For example, if the user entered 2 your output would be:

0

1

If the user entered 5 your output should be:

0

1

1

2

3

Main()

In this program you will need two functions. The first will be main() which will be the starting point of the program. It will take an integer input from the user and print each Fibonacci number up to the position given by the user. The user’s input should be a positive number 1-n. This input should be validated and should continue to prompt the user until a valid input is entered. The body of main should have a similar structure to the code below:

                                                             

num=int(input(“Enter a position”))

                               //Validation Here

                              for i in range((num+1)):

                                      print(fib(i))

Fib()

The fib function should take in an integer contain the position. This will return the Fibonacci number at this location. There should be two base cases and one case with a recursive call. The recursive call should be used to find the values of the two numbers before the one at the given position and so on.

Rubric

10 pts.

Comments and coding style.

50 pts.

Fib() is correct. Both base cases are present, and the recursive call is made correctly.

30 pts.

Menu() correctly prints each Fibonacci number up to and including the position listed.

10 pts.

Menu() correctly validates the user input and makes sure that the input is greater than 0.

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5,...
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
  • The Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8, .......

    The Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8, .... It is defined by the following mathematical expression, with X0 & X1 being 0 and 1, respectively: Xn = Xn-1 + Xn-2 Write a C program using the fork() system call that generates and prints the Fibonacci sequence in the child process. The number of members in the sequence will be determined by a user provided as a user prompted input. Make the parent...

  • The Fibonacci sequence is the sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13,...

    The Fibonacci sequence is the sequence 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. For example, 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). The 5 is found by adding the two numbers before it (2+3), and so on! Each number in the sequence is called...

  • use Java please. The Fibonacci Sequence Given the initial Fibonacci numbers 0 and 1, we can...

    use Java please. The Fibonacci Sequence Given the initial Fibonacci numbers 0 and 1, we can generate the next number by adding the two previous Fibonacci numbers together. For this sequence, you will be asked to take an input, denoting how many Fibonacci numbers you want to generate. Call this input upperFibLimit. The longest Fib sequence you should generate is 40 and the shortest you should generate is 1. So,1<upperFibLimit<40 The rule is simple given f(0) 0, f(1) 1 ....

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

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

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

  • Problem 2: (8 pts) The Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8.,.. Formal...

    Problem 2: (8 pts) The Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8.,.. Formally, it can be expressed as: fib0-0 fibl-1 fibn-fibn-1+fibn-2 Write a multithreaded program that generates the Fibonacci sequence. This program should work as follows: On the command line, the user will enter the number of Fibonacci numbers that the program is to generate. The program will then create a separate thread that will generate the Fibonacci numbers, placing the sequence in...

  • Question 3 Program Language C++ Problem 3 Fibonacci Numbers 10 points Fibonacci numbers are a sequence...

    Question 3 Program Language C++ Problem 3 Fibonacci Numbers 10 points Fibonacci numbers are a sequence of numbers where each number is represented by the sum of the two preceding numbers, starting with 0 and 1: 0, 1, 1, 2, 3, 5, 8, etc Write a program that repeatedly prompts the user for a positive integer and prints out whether or not that integer is a Fibonacci number. The program terminates when-I is entered. Create a method with the following...

  • Check the words in bold. The Fibonacci sequence is the series of numbers 0,1,1, 2, 3,...

    Check the words in bold. The Fibonacci sequence is the series of numbers 0,1,1, 2, 3, 5, 8,.... Formally, it can be expressed as: fib0 = 0 fib1 = 1 fibn = fibn-1 + fibn-2 Write a multithreaded program that generates the Fibonacci sequence using the Win32 thread library(not pthreads because it does not work on windows). This program should work as follows: The user will enter on the command line the number of Fibonacci numbers that the program is...

  • 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

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