Mathematical Expressions (College Board AP® Computer Science Principles): Exam Questions

22 mins22 questions
1
1 mark

A program needs to test whether an integer n is even. Which expression evaluates to true exactly when n is even?

  • n / 2 = 0

  • n MOD 2 = 0

  • n MOD 2 = 1

  • n * 2 = 0

2
1 mark

A program asks the user for two numbers, adds them together, and displays the result. Which algorithm building blocks does this process use?

  • Sequencing only

  • Selection only

  • Sequencing and selection

  • Sequencing, selection, and iteration

3
1 mark

Which of the following is true of all three common ways of expressing an algorithm — natural language, a flowchart, and pseudocode?

  • They can all describe the same algorithm, differing in notation rather than in the algorithm itself

  • Only pseudocode can represent selection and iteration

  • A flowchart can express logic that pseudocode cannot

  • Natural language is the most precise of the three

4
1 mark

Two programs produce identical output. Which feature most improves the readability of one version over the other?

  • Using meaningful variable names such as totalPrice instead of t

  • Writing every statement on a single long line

  • Removing all comments to shorten the program

  • Replacing variable names with single letters to save typing

5
1 mark

What is the value of the following expression?

29 MOD 8
  • 3

  • 8

  • 5

  • 0

6
1 mark

What is the value of the following expression?

7 / 2
  • 3

  • 4

  • 1

  • 3.5

7
1 mark

Consider the following code segment.

total ← 9
count ← 2
average ← total / count
DISPLAY(average)

What value is displayed when this code segment is executed?

  • 4

  • 5

  • 1

  • 4.5

8
1 mark

A program needs to test whether an integer k is a multiple of 3. Which expression evaluates to true exactly when k is a multiple of 3?

  • k / 3 = 0

  • k MOD 3 = 1

  • k * 3 = 0

  • k MOD 3 = 0

9
1 mark

A program repeatedly asks the user to guess a secret number. After each guess it checks whether the guess is correct, and it stops only when the guess matches the secret number. Which algorithm building blocks are used in this process?

  • Iteration only

  • Sequencing, selection, and iteration

  • Selection only

  • Sequencing and selection only

10
1 mark

A program calculates a value correctly but is difficult for others to read. Which change would most improve its readability without changing the program's output?

  • Combining all statements onto a single line to save space

  • Renaming meaningful variable names to single letters

  • Adding a brief comment that explains a non-obvious calculation

  • Removing the blank lines that separate logical sections

1
1 mark

What is the value of the following expression?

20 MOD 6 * 2 + 1
  • 3

  • 5

  • 9

  • 13

2
1 mark

Which two of the following expressions evaluate to exactly 3? Select two answers.

  • 17 MOD 7

  • 12 / 4

  • 10 MOD 4

  • 7 - 5

3
1 mark

Consider the following code segment.

x ← 8
y ← x / 2
x ← y + 6
y ← x - y
DISPLAY(x + y)

What value is displayed?

  • 12

  • 14

  • 16

  • 20

4
1 mark

What value does the following expression evaluate to?

3 + 22 MOD 5 * 4
  • 11

  • 5

  • 0

  • 20

5
1 mark

What value does the following expression evaluate to?

(4 + 5) * 2 - 6 / 3
  • 4

  • 16

  • 12

  • 20

6
1 mark

What value does the following expression evaluate to?

10 MOD 3 + 12 / 4
  • 4

  • 6

  • 1

  • 3

7
1 mark

A clock stores the current hour as an integer h in the range 0 to 11. Which expression gives the hour 5 hours later, wrapping back around to 0 after 11?

  • h + 5 MOD 12

  • (h + 5) MOD 12

  • (h + 5) / 12

  • (h MOD 12) + 5

8
1 mark

Consider the following code segment.

a ← 15
b ← a MOD 4
c ← a / b
DISPLAY(c)

What value is displayed when this code segment is executed?

  • 3

  • 4

  • 5

  • 3.75

9
1 mark

What value does the following expression evaluate to?

(6 + 9) MOD 4 * 2
  • 3

  • 6

  • 8

  • 30

10
1 mark

Consider the following code segment.

x ← 6
x ← x * x
x ← x MOD 7
DISPLAY(x)

What value is displayed when this code segment is executed?

  • 36

  • 5

  • 1

  • 6

1
1 mark

What value does the following expression evaluate to?

8 + 3 * 4 MOD 5 - 1
  • 9

  • 10

  • 3

  • 19

2
1 mark

Consider the following code segment.

p ← 20
q ← p MOD 6
r ← p / 5
s ← q * r
DISPLAY(s)

What value is displayed when this code segment is executed?

  • 8

  • 12

  • 0

  • 4