167k views
5 votes
Return true if the given non-negative number is 1 or 2 more than a multiple of 20. See also: Introduction to Mod

A more20(20) → false
B more20(21) → true
C more20(22) → true

1 Answer

6 votes

Final Answer:

The function `more20` returns true if the given non-negative number is 1 or 2 more than a multiple of 20, and false otherwise. For example, `more20(20)` returns false, `more20(21)` returns true, and `more20(22)` returns true.

Step-by-step explanation:

The function `more20` checks whether the given non-negative number is 1 or 2 more than a multiple of 20. It does so by using the modulo operator `%`, which returns the remainder when the number is divided by 20. If the remainder is 1 or 2, the function returns true, indicating that the number is 1 or 2 more than a multiple of 20. Otherwise, it returns false.

For instance, when `more20(20)` is called, the result is false because 20 is a multiple of 20, and there is no remainder. When `more20(21)` is called, the result is true because 21 is one more than a multiple of 20. Similarly, `more20(22)` returns true since 22 is two more than a multiple of 20.

This function is useful for scenarios where the task involves checking the relationship between a non-negative number and multiples of 20, providing a clear and concise way to express such conditions in code.

User Andreas Engedal
by
8.8k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.