The formal definition of the Fibonacci sequence states that

The formal definition of the Fibonacci sequence states that the sequence begins with the pair of numbers 0 and 1, and then proceeds by consecutively adding the last number with its previous number, getting a new last number. This project is for you to write an algorithm that will take an input from the user of a pair of numbers and check to see if they are adjacent numbers in the Fibonacci sequence. If they are then your algorithm will allow the user to list out a segment of the Fibonacci sequence beginning from those numbers to some point designated by the user. Either a count of x numbers in the sequence or a maximum number not to exceed. For example the user may enter the numbers 3 and 5. As we can see 3 and 5 are in this short segment of the Fibonacci sequence 0, 1, 1, 2, 3, 5. So we could start a new listing of a segment of the Fibonacci sequence beginning with 3 and 5. And if the user were to indicate that the sequence should be 5 numbers long that sequence would be 3, 5, 8, 13, 21. If the user were to enter 3 and 8 your algorithm must identify that the numbers are not an adjacent pair in the Fibonacci sequence.
The formal definition of the Fibonacci sequence states that the sequence begins with the pair of numbers 0 and 1, and then proceeds by consecutively adding the last number with its previous number, getting a new last number. This project is for you to write an algorithm that will take an input from the user of a pair of numbers and check to see if they are adjacent numbers in the Fibonacci sequence. If they are then your algorithm will allow the user to list out a segment of the Fibonacci sequence beginning from those numbers to some point designated by the user. Either a count of x numbers in the sequence or a maximum number not to exceed. For example the user may enter the numbers 3 and 5. As we can see 3 and 5 are in this short segment of the Fibonacci sequence 0, 1, 1, 2, 3, 5. So we could start a new listing of a segment of the Fibonacci sequence beginning with 3 and 5. And if the user were to indicate that the sequence should be 5 numbers long that sequence would be 3, 5, 8, 13, 21. If the user were to enter 3 and 8 your algorithm must identify that the numbers are not an adjacent pair in the Fibonacci sequence.

Solution

//Takes 2 integers as input, and returns True if the 2 numbers are adjacent Fibonacci numbers, and False otherwise.

Algorithm: isAdjacentPair(x, y)

if x == 0 and y == 1 //If the entered numbered are the first and second fibonacci numbers, then return True.

return True.

first := 0, second := 1;

third := first + second;

while third < x: //Keep calculating the next fibonacci numbers, till you reach the first input number.

third = first + second;

first = second;

second = third;

if third == x and second + first == y: //If the first input and second input values are adjacent fibonacci numbers.

return True; //Return true.

return False;

The formal definition of the Fibonacci sequence states that the sequence begins with the pair of numbers 0 and 1, and then proceeds by consecutively adding the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site