209k views
5 votes
The following section of psudo code inputs a number n, multiplies together 1 x 2 x 3 x ..... x n, calculates input number/sum and output result of the calculations.

locate 3 errors and suggest a corrected piece of code.

INPUT n
FOR mult = 1 TO n
sum = 0
sum = sum * mult
result = n / sum
NEXT
PRINT result

User Truefalse
by
4.8k points

1 Answer

4 votes

Answer:

INPUT n

sum = 1

FOR mult = 1 TO n

sum = sum*mult

NEXT

result = n/sum

PRINT result

Step-by-step explanation:

sum should not be defined inside the for loop because it will reset to the initial number after every loop iteration which is not what is desired. Sum should not be 0 if it is being multiplied then divided. This will cause an error. Result should be calculated after sum has settled on a final number, after the loop has finished.

User Alan Effrig
by
4.8k points