A well-kown mathematical property states that a natural number is a multiple of three if and only if the sum of its digits is also a multiple of three. For instance, the sum of the digits of 8472 is , which is a multiple of three. Therefore, 8472 is also a multiple of three.
Implement a recursive function that tells if a strictly positive natural number @n@ is a multiple of three or not.
bool is_multiple_3(int n);
| C++ | |
| C | |
| Java | |
| Python | |
|
Solve this problem using a recursive function to return the sum of the digits of a natural number @n@.
int sum_of_digits(int n);
| C++ | |
| C | |
| Java | |
| Python | |
|
Here, you are allowed to use the operations of division and integer remainder only with the number 10. Otherwise, this exercise would be totally trivial!
Input/Output