128k views
1 vote
If number is defined as an integer, what is the largest value of number%19 ?

User Lwyrn
by
7.2k points

1 Answer

3 votes

The biggest value the expression "number%19" can evaluate to is 18.

From the theory of division with remainder:

D = I * C + R, where R < I and D, I, C, R are natural numbers.

In our case:

  • D = number
  • I = 19
  • C = number/19 (or number//19 if we are talking about Python 3)
  • R = number%19

We can note that R < I, so R < 19. So what is the biggest natural number smaller than 19? Well, most kindergartners will respond 18.

► General rule regarding the % operation:

We can easily prove that a % b will be:

  • At least 0
  • At most b-1
User Bay
by
7.4k points