Ask Question
21 July, 13:28

The Fibonacci numbers are the numbers

(1,1,2,3,5,8,13,21,34)

where the first two numbers are 1 and 1, and each number after that is the sum of the two previous numbers. (So $2 = 1+1$, $3 = 2+1$, and so on.)

Write an algorithm, in English, that takes a positive integer $n$ as input and then outputs the $n$th Fibonacci number. For example, if we input to the algorithm $n=2,$ your algorithm should output 1. If we input $n=6,$ your algorithm should output 8.

Remember that an algorithm should consist of a series of unambiguous steps. Use variable names to identify what values you are referring to. You can assume that the computer can do basic arithmetic.

Above, we have given two input-output examples. Be sure to test your algorithm to see if it can successfully reproduce these examples and any others you care to test.

+1
Answers (1)
  1. 21 July, 16:32
    0
    function fibonacci (n):

    if n is equal to 1 or n is equal to 2:

    return 1

    else:

    return fibonacci (n-1) + fibonacci (n-2)

    end of the function

    Input the n

    Print fibonacci (n)

    Explanation:

    * The above algorithm (pseudocode) is written considering Python.

    Create a function called fibonacci that takes one parameter, n

    If n is equal to 1 or 2, return 1 (When n is 1 or 2, the fibonacci numbers are 1)

    Otherwise, return the sum of the two previous numbers (When n is not 1 or 2, the fibonacci number is equal to sum of the two previous numbers)

    Ask the user for n

    Call the function, pass n as a parameter and print the result
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “The Fibonacci numbers are the numbers (1,1,2,3,5,8,13,21,34) where the first two numbers are 1 and 1, and each number after that is the sum ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers