Modulus Operator Quiz: Using the Modulus Operator in Programming

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Thames
T
Thames
Community Contributor
Quizzes Created: 11092 | Total Attempts: 9,725,533
| Attempts: 11 | Questions: 20 | Updated: May 7, 2026
Please wait...
Question 1 / 21
🏆 Rank #--
0 %
0/100
Score 0/100

1) What is 47 % 3?

Explanation

The largest multiple of 3 that does not exceed 47 is 3 multiplied by 15 equals 45. Subtracting gives 47 minus 45 equals 2. So 47 % 3 equals 2. The modulus operator returns the remainder after integer division. Since 47 divided by 3 gives quotient 15 and remainder 2, the expression evaluates to 2.

Submit
Please wait...
About This Quiz
Math In Coding Quizzes & Trivia

2)

What first name or nickname would you like us to use?

You may optionally provide this to label your report, leaderboard, or certificate.

2) What is 255 % 16?

Explanation

The largest multiple of 16 that does not exceed 255 is 16 multiplied by 15 equals 240. Subtracting gives 255 minus 240 equals 15. So 255 % 16 equals 15. This computation is relevant in low-level programming where 255 is the maximum value of an unsigned byte and 16 is a common block size. The result 15 confirms 255 is one less than a multiple of 16.

Submit

3) For any positive integer n, the expression n % 1 always evaluates to 0.

Explanation

The answer is True. Dividing any integer by 1 gives a quotient equal to the integer itself with no remainder, because 1 divides every integer exactly. In code, n % 1 always returns 0 regardless of the value of n. Every integer can be written as n equals 1 multiplied by n plus 0, making the remainder always 0.

Submit

4) What is 2048 % 7?

Explanation

The largest multiple of 7 that does not exceed 2048 is 7 multiplied by 292 equals 2044. Subtracting gives 2048 minus 2044 equals 4. So 2048 % 7 equals 4. Note that 2048 equals 2 to the power of 11. Using modular arithmetic, 2 mod 7 follows the cycle 2, 4, 1 with period 3. Since 11 mod 3 equals 2, the second term in the cycle is 4, confirming the result.

Submit

5) A hash function maps a key to a table index using the expression key % tableSize. If key equals 157 and tableSize equals 10, what is the resulting index?

Explanation

Applying the hash function: 157 % 10 equals 7, since 10 multiplied by 15 equals 150 and 157 minus 150 equals 7. The index is 7. Using % tableSize ensures the result always falls within the valid index range of 0 to tableSize minus 1. This is a common technique in hash table implementations to map arbitrarily large keys to a fixed-size array.

Submit

6) Which of the following expressions correctly test whether an integer n is divisible by 3 in standard integer arithmetic? (Select all that apply)

Explanation

Option A is correct: n % 3 == 0 returns true exactly when n is divisible by 3, because divisibility means the remainder is 0. Option D is correct: in integer arithmetic, dividing n by 3 and multiplying back by 3 recovers n only when 3 divides n exactly, since integer division truncates any remainder. Option B is incorrect: n % 3 != 1 is true when the remainder is 0 or 2, which includes non-multiples of 3 such as 5. Option C is incorrect: n % 3 == 1 tests for remainder 1, not divisibility by 3.

Submit

7) A program converts a total duration of 7384 seconds into hours and remaining seconds. What is the value of 7384 % 3600?

Explanation

The modulus operation 7384 % 3600 gives the number of seconds remaining after removing complete hours. 3600 multiplied by 2 equals 7200, which is the largest multiple of 3600 not exceeding 7384. Subtracting gives 7384 minus 7200 equals 184. So 7384 % 3600 equals 184, meaning the duration is 2 complete hours and 184 remaining seconds.

Submit

8) In all programming languages, the expression n % 2 == 1 reliably tests whether n is odd for any integer value of n.

Explanation

The answer is False. In programming languages that allow negative integers, a negative odd number such as negative 3 may produce n % 2 equal to negative 1 rather than 1, depending on how the language defines the sign of the remainder. In such languages, n % 2 == 1 would incorrectly return false for negative odd numbers. A more reliable test for oddness is n % 2 != 0, which works correctly for both positive and negative odd integers.

Submit

9) What is 389 % 17?

Explanation

The largest multiple of 17 that does not exceed 389 is 17 multiplied by 22 equals 374. Subtracting gives 389 minus 374 equals 15. So 389 % 17 equals 15. Confirming: 17 multiplied by 22 equals 374, plus 15 equals 389. Since 15 is less than the divisor 17, this is a valid remainder.

Submit

10) A circular queue has size 5. The current head is at index 3. After advancing by 8 positions, what is the new head index?

Explanation

Compute (3 + 8) % 5 equals 11 % 5. 5 multiplied by 2 equals 10; 11 minus 10 equals 1. The new head index is 1. The modulus operation ensures the index wraps correctly within the bounds of the queue. This pattern appears in any fixed-size circular data structure where advancing past the last position returns to the beginning.

Submit

11) For integers i from 0 to 99 inclusive, how many values satisfy i % 7 == 3?

Explanation

Numbers satisfying i % 7 == 3 follow the pattern 3, 10, 17, 24, 31, 38, 45, 52, 59, 66, 73, 80, 87, 94, each 7 more than the previous. The last value 94 is less than 100, and the next value 101 falls outside the range. Counting gives exactly 14 values, each written as 7k plus 3 for k from 0 to 13.

Submit

12) What is 1001 % 11?

Explanation

11 multiplied by 91 equals 1001 exactly. So 1001 % 11 equals 0. This means 1001 is exactly divisible by 11, and the modulus operator returns 0. In programming, a result of 0 from the modulus operator confirms that the dividend is a perfect multiple of the divisor, which is the standard way to test for exact divisibility using the condition value % divisor == 0.

Submit

13) For integers i from 0 to n minus 1 inclusive, exactly one value of i satisfies i % n == 0, and that value is i equals 0.

Explanation

The answer is True. Within the range 0 to n minus 1, every value of i is already less than n, so i % n equals i for all values in this range. The expression i % n == 0 only holds when i itself equals 0, since no other value from 1 to n minus 1 is divisible by n. This property is useful in loops that need to trigger an action exactly once at the start of each new cycle of length n.

Submit

14) What is 723 % 8?

Explanation

The largest multiple of 8 that does not exceed 723 is 8 multiplied by 90 equals 720. Subtracting gives 723 minus 720 equals 3. So 723 % 8 equals 3. In a programming context this could represent the byte offset of position 723 within 8-byte aligned memory blocks, where a result of 3 means the position is 3 bytes into the current block.

Submit

15) Which of the following statements about the expression i % 5 are always true for any non-negative integer i? (Select all that apply)

Explanation

Option A is true: the modulus operator with divisor 5 always returns a value from 0 to 4 inclusive by the definition of integer remainder. Option B is true: when i is less than 5, dividing by 5 gives quotient 0 and remainder i, so i % 5 equals i. Option C is false: when i is a multiple of 5 such as 0, 5, or 10, the result is 0, which is not greater than 0. Option D is true: two integers share the same remainder when divided by 5 if and only if their difference is divisible by 5.

Submit

16) What is 284 % 15?

Explanation

The largest multiple of 15 that does not exceed 284 is 15 multiplied by 18 equals 270. Subtracting gives 284 minus 270 equals 14. So 284 % 15 equals 14. In a programming context this result represents a position within a 15-element circular structure, confirming that element 284 maps to the same slot as element 14 in a zero-indexed array of length 15.

Submit

17) For integers i from 1 to 30 inclusive, how many values satisfy both i % 6 == 0 and i % 4 == 0 simultaneously?

Explanation

A number satisfying both i % 6 == 0 and i % 4 == 0 must be divisible by both 6 and 4. The smallest such number is LCM(6, 4) equals 12. Within 1 to 30, the multiples of 12 are 12 and 24, giving exactly 2 values. In code, this combined condition is equivalent to i % 12 == 0, since any number divisible by both 6 and 4 must be divisible by their least common multiple.

Submit

18) Applying the modulus operator twice as in (a % n) % n always gives a different result from applying it once as in a % n.

Explanation

The answer is False. The expression a % n returns a value r where 0 is less than or equal to r and r is less than n. Applying % n again to r gives r % n, which equals r because r is already less than n. So (a % n) % n always equals a % n. In programming this means applying the modulus operator a second time is redundant and produces no change to the value.

Submit

19) What is 500 % 13?

Explanation

The largest multiple of 13 that does not exceed 500 is 13 multiplied by 38 equals 494. Subtracting gives 500 minus 494 equals 6. So 500 % 13 equals 6. Confirming: 13 multiplied by 38 equals 494, plus 6 equals 500. Since 6 is less than the divisor 13, this is a valid remainder.

Submit

20) A program applies a striped pattern to rows indexed 0 to 9. Rows where i % 2 equals 1 are coloured grey. How many rows are grey?

Explanation

Rows where i % 2 equals 1 are the odd-indexed rows: 1, 3, 5, 7, and 9. Counting gives exactly 5 grey rows. The even-indexed rows 0, 2, 4, 6, and 8 satisfy i % 2 equals 0 and are not grey. This alternating pattern using the modulus operator is a common technique for applying striped styling in programming, such as alternating row colours in a data table.

Submit
×
Saved
Thank you for your feedback!
View My Results
Cancel
  • All
    All (20)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What is 47 % 3?
What is 255 % 16?
For any positive integer n, the expression n % 1 always evaluates to...
What is 2048 % 7?
A hash function maps a key to a table index using the expression key %...
Which of the following expressions correctly test whether an integer n...
A program converts a total duration of 7384 seconds into hours and...
In all programming languages, the expression n % 2 == 1 reliably tests...
What is 389 % 17?
A circular queue has size 5. The current head is at index 3. After...
For integers i from 0 to 99 inclusive, how many values satisfy i % 7...
What is 1001 % 11?
For integers i from 0 to n minus 1 inclusive, exactly one value of i...
What is 723 % 8?
Which of the following statements about the expression i % 5 are...
What is 284 % 15?
For integers i from 1 to 30 inclusive, how many values satisfy both i...
Applying the modulus operator twice as in (a % n) % n always gives a...
What is 500 % 13?
A program applies a striped pattern to rows indexed 0 to 9. Rows where...
play-Mute sad happy unanswered_answer up-hover down-hover success oval cancel Check box square blue
Alert!