Question: Question 7 The pseudo code below contains an error. What is the error? A ) The function is _ in _ fibonacci makes the wrong

Question 7
The pseudo code below contains an error. What is the error?
A) The function is_in_fibonacci makes the wrong comparison.
B) The function main mishandles the user input.
C) The loop condition in function generate_fibonacci is faulty.
D) The function generate_fibonacci isn't initialising fib_sequence correctly.
FUNCTION generate_fibonacci(n)
INITIALISE fib_sequence TO [0,1]
WHILE last element of fib_sequence < n THEN DO
CALCULATE new_fib_value AS fib_sequence[LAST_INDEX(fib_sequence)]+ fib_sequence[SECOND_LAST_INDEX(fib_sequence)]
APPEND new_fib_value TO fib_sequence
END
RETURN fib_sequence
FUNCTION is_in_fibonacci(number, fib_sequence)
IF number = fib_sequence THEN DO
RETURN True
ELSE DO
RETURN False
END
FUNCTION main()
PRINT "Welcome to the Fibonacci Sequence Checker"
PRINT "Enter an integer to check if it is in the Fibonacci sequence: "
GET input FROM USER
WHILE input IS NOT AN INTEGER THEN DO
PRINT "That input was not a valid integer. Please enter an integer: "
GET input FROM USER
END
SET check_number TO input
CALCULATE fibonacci_sequence AS generate_fibonacci(check_number)
IF is_in_fibonacci(check_number, fibonacci_sequence)= True THEN DO
PRINT check_number " is in the Fibonacci sequence!"
ELSE DO
PRINT check_number " is not in the Fibonacci sequence."
END
main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!