Past-paper question · 2016 May-June · Paper 22 · Q2(d)

Question 2(d) 2016 · May-June · Paper 22 · 4 marks

Original past-paper question for 2(D)
Original past-paper question for 2(D)
Original past-paper question for 2(D)
Reveal official mark-scheme answer Official mark-scheme answer for 2(D)

Official answer for Question 2

Part (d)

Part (d)

No marks for recursive solutions

[4]
✓
FUNCTION Power(Number : INTEGER, Exponent : INTEGER) RETURNS INTEGER
✓
Result ← 1
✓
IF Exponent > 0
✓
THEN
✓
FOR e ← 1 to Exponent
✓
Result ← Result * Number
✓
ENDFOR
✓
ENDIF
✓
RETURN Result
✓
ENDFUNCTION
✓
Alternative:
✓
FUNCTION Power(Number : INTEGER, Exponent : INTEGER) RETURNS INTEGER
✓
Result ← 1
✓
IF Exponent > 0
✓
THEN
✓
e ← Exponent
✓
REPEAT
✓
Result ← Result * Number
✓
e ← e - 1
✓
UNTIL e = 0
✓
ENDIF
✓
RETURN Result
✓
ENDFUNCTION
✓
FUNCTION Power(Number : INTEGER, Exponent : INTEGER) RETURNS INTEGER
✓
Result ← 1
✓
e ← Exponent
✓
WHILE e > 0
✓
Result ← Result * Number
✓
e ← e - 1
✓
ENDWHILE
✓
RETURN Result
✓
ENDFUNCTION

Mark scheme 9691_s16_ms_22.pdf →

Show text version of question

Question 2

Part (d)

Question 2

Ryan wrote the following recursive function using pseudocode.

01 FUNCTION Power(Number : INTEGER, Exponent : INTEGER) RETURNS INTEGER 02 IF Exponent = 0 03 THEN 04 Result ← 1 05 ELSE 06 Result ← Number * Power(Number, Exponent - 1) 07 ENDIF 08 RETURN Result 09 ENDFUNCTION

Part (d)

An alternative method for the Power function is to use an iterative solution.

Using pseudocode, write Power as an iterative function.

FUNCTION Power(Number : INTEGER, Exponent : INTEGER) RETURNS INTEGER

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

..............................................................................................................................................

[4]
Topic relevance

Why this question appears here

98% assigned-topic match · Computational thinking and problem-solving › Recursion

Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.

Permanent source page: Educate A Change · From 9691_s16_qp_22.pdf

Keep practising this topic