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
11 Respuestas
+ 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
+ 1
It would be 0
+ 1
Minenhle Simphiwe so I gave you an idea with string, you can do it using for loop
0
What does the modulo(%) operator do ?
0
it returns the remainder
0
And what will be the remainder if the number is perfectly divisible ?
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
0
Arvind
Your Code Will Run But It Will Only Display True Or False Then The int input Is Entered..Thanks Though
0
Arvind Okey Thank You