1
I have to do a function that tests divisibility by 3, return true
if divisible by 3. Otherwise return false
. Following the rule : A number is divisible by 3 when the sum of its digits is divisible by three.
I have the following variables: :
int dividendo;
int divisor;
And I have the following function :
int divisibilidade3(int num);
I need to separate the digits from the variable dividendo
, for example, when the user enters with the splitter 3
I’ll call the function divisibilidade3
and I will check if the final digit ends with 3, 6 or 9.
For example, if the user enters the number 25848
, I need to break this number into pieces, being then : 2+5+8+4+8 = 27 e 2+7 = 9
, how is it 9
the final result, then it is divisible by 3.
The function should repeat the digit summation process of the results obtained until the sum is a number with one digit. If this digit is 3, 6 or 9, so the original number is divisible by 3.
I will have to follow all these rules using divisibility criteria. If anyone can help me, I am grateful.
If I understand correctly, you want to create a function that shows that a given number is divisible by 3, you cannot use the mod?
– Marconi
I can use mod to some extent, but I can’t check for example whether %b == 0 is divisible or not. I have to follow the divisibility criteria.
– Mondial
The mod indicates the rest of the division, if it is
0
means that the number is divisible by the value.– Marconi