Skip to content
MathsGenie logo
Open app

Course home

  1. IGCSE
  2. Computer Science Edexcel
  3. Question bank

Subprograms

EasyMedium
123456789101112131415161718192021222324252627282930
Question 12

The pseudocode below shows a function used to calculate the power of a base number raised to an exponent.

1 FUNCTION calcPower(baseNumber, exponentValue)
2 BEGIN FUNCTION
3     IF exponentValue < 0 THEN
4         powerResult = 0
5     ELSE
6         powerResult = 1
7         FOR iteration FROM 1 TO exponentValue DO
8             powerResult = powerResult * baseNumber
9         END FOR
10    END IF
11    RETURN powerResult
12 END FUNCTION
13
14 SEND "Enter a base: " TO DISPLAY
15 RECEIVE userBase FROM (INTEGER) KEYBOARD
16 SEND "Enter an exponent: " TO DISPLAY
17 RECEIVE userExponent FROM (INTEGER) KEYBOARD
18 SET finalOutput TO calcPower(userBase, userExponent)
19 SEND ("Result is: " & finalOutput) TO DISPLAY

Identify the name of one local variable used in this pseudocode.

[1]

Subprograms Questions

  1. IGCSE
  2. /Computer Science
  3. /Subprograms