0

How to test for divisibility by 3 from taking user input and sum the digits

A common test for divisibility by 3 is to add the digits of an integer. If the resulting sum is divisible by 3 then so is the original number. Program this test. The sum must be < 20 i.e. if the sum is >= 20, then the digits of the resulting sum must be added. It should repeat this procedure until the sum is < 20. The program should input a number from the user and print out whether or not the number is divisible by 3

12th May 2021, 7:59 AM
Minenhle Simphiwe
Minenhle Simphiwe - avatar
11 Respostas
+ 1
Why would you sum these digits? Just use modulo. Anyway, if I had to, I would take input as string, iterate thru it casting each position to int and adding them to sum
12th May 2021, 8:08 AM
Michal Doruch
+ 1
It would be 0
12th May 2021, 8:08 AM
Minenhle Simphiwe
Minenhle Simphiwe - avatar
+ 1
Minenhle Simphiwe so I gave you an idea with string, you can do it using for loop
12th May 2021, 8:14 AM
Michal Doruch
0
What does the modulo(%) operator do ?
12th May 2021, 8:00 AM
Arsenic
Arsenic - avatar
0
it returns the remainder
12th May 2021, 8:03 AM
Minenhle Simphiwe
Minenhle Simphiwe - avatar
0
And what will be the remainder if the number is perfectly divisible ?
12th May 2021, 8:04 AM
Arsenic
Arsenic - avatar
0
Juan Pablo Segundo I wanna use the 3 divisibility Rule actually that's why I sum the digits I wanna know how to use the for loop to come to an answer
12th May 2021, 8:12 AM
Minenhle Simphiwe
Minenhle Simphiwe - avatar
0
Arvind Your Code Will Run But It Will Only Display True Or False Then The int input Is Entered..Thanks Though
12th May 2021, 8:17 PM
Minenhle Simphiwe
Minenhle Simphiwe - avatar
0
Arvind Okey Thank You
13th May 2021, 6:39 AM
Minenhle Simphiwe
Minenhle Simphiwe - avatar