94.6k views
3 votes
Debug the following program.

REM "Program to generate 2 2 4 6 10. 16... up to 10th terms" CLS

A=2

B=3

For I=1 to 10

Display A; B;

A=A+B

B=A+B

NEXT X

END​

1 Answer

1 vote

Answer:

The debugged program is as follows:

A=2

B=2

For I=1 to 10

PRINT A

TEMP = A

A=B

B=TEMP+A

NEXT I

END

Step-by-step explanation:

First, the value of B should be changed to 4 (because the second term of the sequence is 2

Next, change Display to Print because Q-basic uses the print keyword to display output

The sequence is not properly generated. So, I update that part of the program to:

For I=1 to 10

PRINT A

TEMP = A

A=B

B=TEMP+A

NEXT I

Lastly, the loop is controlled by variable I (not X).

So change NEXT X to NEXT I

User John Salvatier
by
3.6k points