Question: Question 7 The pseudo code below contains an error. What is the error? A ) The function is _ in _ fibonacci makes the wrong
Question
The pseudo code below contains an error. What is the error?
A The function isinfibonacci makes the wrong comparison.
B The function main mishandles the user input.
C The loop condition in function generatefibonacci is faulty.
D The function generatefibonacci isn't initialising fibsequence correctly.
FUNCTION generatefibonaccin
INITIALISE fibsequence TO
WHILE last element of fibsequence n THEN DO
CALCULATE newfibvalue AS fibsequenceLASTINDEXfibsequence fibsequenceSECONDLASTINDEXfibsequence
APPEND newfibvalue TO fibsequence
END
RETURN fibsequence
FUNCTION isinfibonaccinumber fibsequence
IF number fibsequence 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 checknumber TO input
CALCULATE fibonaccisequence AS generatefibonaccichecknumber
IF isinfibonaccichecknumber, fibonaccisequence True THEN DO
PRINT checknumber is in the Fibonacci sequence!"
ELSE DO
PRINT checknumber 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
