AP Computer Science A Practice Quiz: Implementing Selection and Iteration Algorithms
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Test your understanding with short quizzes. This quiz has 7 questions to check your progress.
Question 1 of 7
All Questions (7)
A) 5
B) 10
C) 49
D) 50
Correct Answer: B
This algorithm determines the frequency with which a specific criterion is met. The code iterates through integers from 1 to 50. The counter `count` is incremented each time an integer `i` is evenly divisible by 5 (i.e., `i MOD 5 = 0`). The numbers that satisfy this condition are 5, 10, 15, 20, 25, 30, 35, 40, 45, and 50. There are 10 such numbers, so the final value of `count` is 10.
A) 384
B) 12
C) 15
D) 96
Correct Answer: C
This is a standard algorithm for identifying and processing individual digits in an integer. Let's trace the execution with num = 384: 1. Loop 1: digit = 384 % 10 = 4. sum = 0 + 4 = 4. num = 384 / 10 = 38. 2. Loop 2: digit = 38 % 10 = 8. sum = 4 + 8 = 12. num = 38 / 10 = 3. 3. Loop 3: digit = 3 % 10 = 3. sum = 12 + 3 = 15. num = 3 / 10 = 0. The loop terminates because num is now 0. The final value of `sum`, which is 15, is displayed.
A) 100
B) 25
C) 21
D) 12
Correct Answer: D
This algorithm is designed to determine a minimum value from a sequence. The variable `minVal` is initialized to 100. The algorithm then iterates through the sequence, updating `minVal` whenever a smaller value is encountered. 1. `currentVal` is 25. 25 < 100 is true. `minVal` becomes 25. 2. `currentVal` is 18. 18 < 25 is true. `minVal` becomes 18. 3. `currentVal` is 32. 32 < 18 is false. 4. `currentVal` is 12. 12 < 18 is true. `minVal` becomes 12. 5. `currentVal` is 21. 21 < 12 is false. After all inputs are processed, the final value of `minVal` is 12.
A) It computes the sum of the digits in `num`.
B) It determines the largest digit in `num`.
C) It determines the number of digits in `num` that are greater than 5.
D) It determines if `num` is evenly divisible by 5.
Correct Answer: C
This algorithm iterates through the individual digits of `num` using the standard `MOD 10` and `/ 10` technique. Inside the loop, it uses a selection statement (`IF`) to check if the current `digit` meets a specific criterion, which is being greater than 5. A counter, `count`, is incremented only when this criterion is met. Therefore, the algorithm determines the frequency of digits that are greater than 5.
A) 16
B) 24
C) 30
D) 21
Correct Answer: C
This algorithm combines finding a maximum value with a selection criterion (the number must be even). `maxEven` is initialized to -1. 1. Input: 17 (odd). No change. 2. Input: 24 (even). 24 > -1 is true. `maxEven` becomes 24. 3. Input: 9 (odd). No change. 4. Input: 30 (even). 30 > 24 is true. `maxEven` becomes 30. 5. Input: 21 (odd). No change. 6. Input: 16 (even). 16 > 30 is false. No change. The final value of `maxEven` is 30.
A) 10
B) 12
C) 5
D) 60
Correct Answer: B
This algorithm computes an average for values meeting a specific criterion. First, it identifies all numbers between 1 and 20 that are divisible by 4: 4, 8, 12, 16, 20. The `sum` variable accumulates these values: 4 + 8 + 12 + 16 + 20 = 60. The `count` variable tracks how many such numbers there are, which is 5. Finally, the average is computed as `sum / count`, which is 60 / 5 = 12.
A) Segment A
B) Segment B
C) Segment C
D) Segment D
Correct Answer: B
This question requires developing an original algorithm based on a definition. To find the sum of proper divisors, we must iterate through numbers less than `n` and check for divisibility. - Segment A is incorrect because its loop goes up to `n`, incorrectly including `n` itself in the sum. - Segment B is correct. It initializes a sum to 0, iterates from 1 up to `n-1`, adds `i` to the sum if `i` is a divisor, and finally compares the sum to `n`. - Segment C is incorrect because it includes `n` in the sum of its divisors, so the sum will always be greater than `n` (for n>1). - Segment D is incorrect because the condition `i MOD n = 0` will only be true for `i=0` (if the loop started there), not for any positive `i` less than `n`.