ProgrammingVery hard
For the signed integer -17, which expression gives the non-negative remainder modulo 5 in C?
- A. -17 % 5
- B. (-17 / 5) * 5
- C. ((-17 % 5) + 5) % 5
- D. -17 >> 2
Correct answer: C. ((-17 % 5) + 5) % 5
C99 gives -17 % 5 = -2, which is negative. Adding 5 and taking % again yields 3, the mathematical residue.
More C Programming questions
- In 32-bit signed int arithmetic, what is the largest n such that the sum 1 + 2 + ... + n does not overflow?
- How many integers from 1 to 100 are divisible by 6 or by 9?
- With 32-bit unsigned int, what is 65536u 65536u?
- Exponentiation by squaring computes x^1000 with how many multiplications at most, counting squarings and the result multiplications?
- In ASCII, what is 'k' ^ 32 as a character?
- In a 32-bit unsigned int, what is (~0u) >> 28?