Bird
0
0
DSA Cprogramming~5 mins

Modular Arithmetic Basics in DSA C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is modular arithmetic?
Modular arithmetic is a system of arithmetic for integers where numbers wrap around after reaching a certain value called the modulus.
Click to reveal answer
beginner
What does the expression 'a % m' mean in modular arithmetic?
It means the remainder when integer 'a' is divided by the modulus 'm'. This remainder is always between 0 and m-1.
Click to reveal answer
beginner
How do you add two numbers under modulus m?
Add the two numbers normally, then take the remainder when divided by m: (a + b) % m.
Click to reveal answer
beginner
What is the result of (a * b) % m?
Multiply a and b normally, then take the remainder when divided by m: (a * b) % m.
Click to reveal answer
intermediate
Why is modular arithmetic useful in programming?
It helps keep numbers within a fixed range, prevents overflow, and is used in hashing, cryptography, and cyclic structures.
Click to reveal answer
What is the value of 17 % 5?
A5
B3
C2
D0
Which of these is true for modular addition?
A(a + b) % m = ((a % m) + (b % m)) % m
B(a + b) % m = (a + b)
C(a + b) % m = (a % b) % m
D(a + b) % m = (a % m) * (b % m)
What is (4 * 6) % 5?
A2
B4
C3
D1
If a % m = 3 and b % m = 4, what is (a + b) % m?
A(3 + 4) % m
B0
CCannot determine
D7
Which of these is NOT a use of modular arithmetic?
ACryptography
BHashing functions
CPreventing integer overflow
DSorting arrays
Explain how modular addition works and why it is useful.
Think about adding two numbers and then wrapping around a fixed number.
You got /3 concepts.
    Describe a real-life example where modular arithmetic is used.
    Consider how hours reset after 12 or 24.
    You got /3 concepts.