Figure 2 shows an algorithm that uses integer division which has been represented using pseudo-code - AQA - GCSE Computer Science - Question 2 - 2023 - Paper 1
Question 2
Figure 2 shows an algorithm that uses integer division which has been represented using pseudo-code.
- Line numbers are included but are not part of the algorithm.
... show full transcript
Worked Solution & Example Answer:Figure 2 shows an algorithm that uses integer division which has been represented using pseudo-code - AQA - GCSE Computer Science - Question 2 - 2023 - Paper 1
Step 1
Where is iteration first used in the algorithm in Figure 2?
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Iteration is first used in the algorithm at Line number 6 where the inner WHILE loop begins, checking the condition a > 0.
Step 2
In the algorithm in Figure 2, what will be output when the user input is 10?
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
When the user inputs 10, the algorithm divides 10 by 3 iteratively. The value of a will change as follows:
10 DIV 3 = 3
3 DIV 3 = 1
1 DIV 3 = 0
The final output will be 1.
Step 3
In the algorithm in Figure 2, what is the largest possible value of the variable counter when the user input is 36?
96%
101 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The largest value of counter occurs when we start from 36:
36 DIV 3 = 12
12 DIV 3 = 4
4 DIV 3 = 1
1 DIV 3 = 0
Thus, counting the iterations:
From 36 to 12 (1)
From 12 to 4 (2)
From 4 to 1 (3)
From 1 to 0 (4)
This means the largest possible value of counter is 4.