Difference between revisions of "2016 New Spec"
(→Figure 4) |
(→AS Question 5) |
||
Line 3: | Line 3: | ||
'''Example:''' calculating the additive persistence of 87 | '''Example:''' calculating the additive persistence of 87 | ||
− | 8 + 7 = 15 | + | 8 + 7 = 15 |
1 + 5 = 6 | 1 + 5 = 6 | ||
After 2 steps the method results in a one digit answer so the additive persistence of 87 is 2. | After 2 steps the method results in a one digit answer so the additive persistence of 87 is 2. | ||
Line 11: | Line 11: | ||
2 * 7 = 14 | 2 * 7 = 14 | ||
1 * 4 = 4 | 1 * 4 = 4 | ||
− | After 3 steps the method results in a one digit answer so the multiplicative persistence of 39 is 3. | + | After 3 steps the method results in a one digit answer so the multiplicative persistence of 39 is 3. |
=Figure 4= | =Figure 4= |
Latest revision as of 14:08, 29 November 2016
AS Question 5
The algorithm, represented using pseudo-code in Figure 4, describes a method to calculate the additive or multiplicative persistence of a two-digit integer. The examples below illustrate how additive and multiplicative persistence are calculated.
Example: calculating the additive persistence of 87
8 + 7 = 15 1 + 5 = 6
After 2 steps the method results in a one digit answer so the additive persistence of 87 is 2.
Example: calculating the multiplicative persistence of 39
3 * 9 = 27 2 * 7 = 14 1 * 4 = 4
After 3 steps the method results in a one digit answer so the multiplicative persistence of 39 is 3.
Figure 4
OUTPUT "Enter integer (0-99): "
INPUT Value
OUTPUT "Calculate additive or multiplicative persistence (a or m)? "
INPUT Operation
Count = 0
WHILE Value > 9
- IF Operation = "a" THEN
- Value = (Value DIV 10) + (Value MOD 10)
- Value = (Value DIV 10) + (Value MOD 10)
- ELSE
- Value = (Value DIV 10) * (Value MOD 10)
- Value = (Value DIV 10) * (Value MOD 10)
- ENDIF
- Count = Count + 1
ENDWHILE
OUTPUT "The persistence is: "
OUTPUT Count
The MOD operator calculates the remainder resulting from an integer division, for example, 10 MOD 3 = 1. The DIV operator calculates integer division, for example 10 DIV 3 = 3.
What you need to do
- Write a program for the algorithm in Figure 4.
- Test the program by showing the result of entering 47, followed by m when prompted by the program.
- Test the program by showing the result of entering 77, followed by a when prompted by the program.