Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to compute the remainder of 17 divided by 5.
DSA C#
int result = 17 [1] 5; Console.WriteLine(result);
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/' instead of '%' results in quotient, not remainder.
Using '*' or '+' operators which do not compute remainder.
✗ Incorrect
The % operator gives the remainder of division, so 17 % 5 equals 2.
2fill in blank
mediumComplete the code to check if a number is divisible by 3 using modular arithmetic.
DSA C#
bool isDivisible = (number [1] 3) == 0;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/' instead of '%' to check divisibility.
Comparing remainder to 1 instead of 0.
✗ Incorrect
Using '%' gives the remainder. If remainder is 0, number is divisible by 3.
3fill in blank
hardFix the error in the code to correctly compute (a + b) mod m.
DSA C#
int modSum = (a [1] b) % m;Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' or '*' instead of '+' inside the parentheses.
Taking modulo before adding.
✗ Incorrect
To add two numbers modulo m, add them first then take modulo m.
4fill in blank
hardFill both blanks to compute (a * b) mod m correctly.
DSA C#
int modProduct = (a [1] b) [2] m;
Attempts:
3 left
💡 Hint
Common Mistakes
Taking modulo before multiplication.
Using '+' or '-' instead of '*' for multiplication.
✗ Incorrect
Multiply a and b first, then take modulo m to get the product modulo m.
5fill in blank
hardFill all three blanks to create a dictionary mapping a number to its square modulo 10.
DSA C#
var squaresMod = new Dictionary<int, int>() {
{ [1], ([2] * [3]) % 10 }
};Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables for key and value.
Forgetting modulo operator after squaring.
✗ Incorrect
Use 'i' as key and value, square i then take modulo 10 for the value.
