Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to compute the remainder of 10 divided by 3.
DSA C
int result = 10 [1] 3; printf("%d\n", result);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using / instead of % will give the quotient, not remainder.
Using * or + will not compute remainder.
✗ Incorrect
The % operator gives the remainder of division in C.
2fill in blank
mediumComplete the code to compute (7 + 5) modulo 6.
DSA C
int sum = (7 + 5) [1] 6; printf("%d\n", sum);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using / will give quotient, not remainder.
Using * or - will not compute modulo.
✗ Incorrect
The modulo operator % gives the remainder after division, so (7+5)%6 = 12%6 = 0.
3fill in blank
hardFix the error in the code to correctly compute (a * b) modulo m.
DSA C
int mod_mul(int a, int b, int m) {
return (a [1] b) % m;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + or - will add or subtract instead of multiply.
Using / will cause division error or wrong result.
✗ Incorrect
To multiply a and b before modulo, use the * operator.
4fill in blank
hardFill both blanks to compute (x - y) modulo n correctly, handling negative results.
DSA C
int mod_sub(int x, int y, int n) {
int diff = (x [1] y) % n;
return diff [2] 0 ? diff + n : diff;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of - for subtraction.
Checking > 0 instead of < 0 for negative.
✗ Incorrect
Subtract y from x, then if result is negative (less than 0), add n to keep it positive modulo.
5fill in blank
hardFill all three blanks to create a function that computes (a^b) modulo m using fast exponentiation.
DSA C
int mod_pow(int a, int b, int m) {
int result = 1;
a = a [1] m;
while (b > 0) {
if (b [2] 1) result = (result * a) % m;
a = (a * a) % m;
b = b [3] 1;
}
return result;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using / instead of >> for shifting.
Using + or - instead of & for bit check.
Not applying modulo after multiplication.
✗ Incorrect
Use modulo to keep a in range, bitwise & 1 to check odd b, and right shift >> 1 to divide b by 2.
