Modular arithmetic is a way of doing math where numbers wrap around after reaching a certain value called the modulus. Think of a clock where after 12 comes 1 again.
Click to reveal answer
beginner
What does the expression 17 % 5 equal?
17 % 5 equals 2 because when you divide 17 by 5, the remainder is 2.
Click to reveal answer
beginner
Why is modular arithmetic useful in programming?
It helps keep numbers within a fixed range, like cycling through array indexes or handling large numbers without overflow.
Click to reveal answer
intermediate
How do addition and multiplication work under modular arithmetic?
You add or multiply numbers normally, then take the remainder after dividing by the modulus. For example, (7 + 8) % 5 = 0 and (4 * 3) % 5 = 2.
Click to reveal answer
intermediate
What is the result of (a % m + b % m) % m?
It equals (a + b) % m. This shows modular addition is consistent and can be broken down into parts.
Click to reveal answer
What is 23 % 7?
A3
B4
C2
D5
✗ Incorrect
23 divided by 7 is 3 with remainder 2, so 23 % 7 = 2. The correct answer is B.
Which operation is NOT valid in modular arithmetic?
AMultiplication
BSubtraction
CAddition
DDivision without inverse
✗ Incorrect
Division in modular arithmetic requires an inverse, so division without inverse is not valid.
If a % m = 3 and b % m = 4, what is (a + b) % m?
ACannot determine
B1
C7
D0
✗ Incorrect
Without knowing m, we cannot determine (a + b) % m exactly.
What does the modulus operator (%) return?
AQuotient
BRemainder
CProduct
DDifference
✗ Incorrect
The modulus operator returns the remainder after division.
Which of these is a real-life example of modular arithmetic?
AReading a 12-hour clock
BCounting money
CMeasuring weight
DCalculating age in years
✗ Incorrect
A 12-hour clock resets after 12, which is modular arithmetic.
Explain modular arithmetic and give a simple example.
Think about how a clock resets after 12.
You got /3 concepts.
Describe how addition works in modular arithmetic with an example.
Add numbers first, then apply modulus.
You got /3 concepts.
Practice
(1/5)
1. What is the result of 17 % 5 in modular arithmetic?
easy
A. 2
B. 3
C. 5
D. 0
Solution
Step 1: Understand the modulus operation
The modulus operator (%) gives the remainder after division of the first number by the second.
Step 2: Calculate 17 % 5
Dividing 17 by 5 gives 3 with a remainder of 2.
Final Answer:
2 -> Option A
Quick Check:
17 % 5 = 2 [OK]
Hint: Modulus gives remainder after division [OK]
Common Mistakes:
Confusing modulus with division result
Using quotient instead of remainder
Thinking modulus returns zero if not divisible
2. Which of the following is the correct syntax to compute the modulus of two integers a and b in C#?
easy
A. int result = a & b;
B. int result = a mod b;
C. int result = a / b;
D. int result = a % b;
Solution
Step 1: Recall C# modulus operator
In C#, the modulus operator is the percent sign (%).
Step 2: Check each option
int result = a % b; uses % correctly. int result = a mod b; uses 'mod' which is not valid syntax. int result = a / b; uses division (/), not modulus. int result = a & b; uses bitwise AND (&), unrelated to modulus.
Final Answer:
int result = a % b; -> Option D
Quick Check:
C# modulus syntax = a % b [OK]
Hint: Use % symbol for modulus in C# [OK]
Common Mistakes:
Using 'mod' keyword instead of %
Confusing division (/) with modulus (%)
Using bitwise operators (&) mistakenly
3. What is the output of the following C# code?
int a = 14;
int b = 4;
int c = (a + b) % 5;
Console.WriteLine(c);
medium
A. 2
B. 4
C. 3
D. 1
Solution
Step 1: Calculate sum inside parentheses
a + b = 14 + 4 = 18.
Step 2: Compute modulus 18 % 5
18 divided by 5 is 3 remainder 3, so 18 % 5 = 3.
Final Answer:
3 -> Option C
Quick Check:
(14 + 4) % 5 = 3 [OK]
Hint: Add first, then apply modulus [OK]
Common Mistakes:
Applying modulus before addition
Confusing remainder with quotient
Incorrect arithmetic calculation
4. Identify the error in the following C# code snippet that tries to compute modulus:
int x = 10;
int y = 3;
int result = x % y;
medium
A. No error, code is correct
B. Missing semicolon after the first line
C. Using % operator with integers is invalid
D. Variables x and y must be declared as double
Solution
Step 1: Check syntax correctness
Each line ends with a semicolon; variables are declared as integers.
Step 2: Validate modulus usage
The modulus operator (%) works correctly with integers in C#.
Final Answer:
No error, code is correct -> Option A
Quick Check:
Modulus with int variables is valid [OK]
Hint: Modulus works with int types and needs semicolons [OK]
Common Mistakes:
Thinking % is invalid for integers
Missing semicolons (not in this code)
Using floating types unnecessarily
5. You want to find the remainder when the sum of all numbers from 1 to 100 is divided by 7. Which C# expression correctly computes this using modular arithmetic?
hard
A. int result = 100 * (101 % 7) / 2;
B. int result = (100 * 101 / 2) % 7;
C. int result = (100 % 7) * (101 % 7) / 2;
D. int result = (100 + 101) % 7 / 2;
Solution
Step 1: Recall formula for sum 1 to n
The sum of numbers from 1 to 100 is n(n+1)/2 = 100*101/2.
Step 2: Apply modulus after full sum calculation
Compute (100*101/2) % 7 to get the remainder after division by 7.
Final Answer:
int result = (100 * 101 / 2) % 7; -> Option B
Quick Check:
Sum formula then modulus = correct [OK]
Hint: Calculate full sum first, then apply modulus [OK]
Common Mistakes:
Applying modulus before multiplication or division
Incorrect order of operations
Dividing before multiplying causing wrong result
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.