Question: Write a program that uses a math shortcut to decide if an integer is divisible by 3. First sum the digits of the number. Youll

Write a program that uses a math shortcut to decide if an integer is divisible by 3. First sum the digits of the number. Youll need a loop along with / and % operators to extract the digits. For example: 1234 is 1+2+3+4, which is 10.
If the sum is divisible by 3, then the entire number is divisible by 3. For example, 1234 has a digit sum of 10. Since 3 does not evenly divide into 10, 1234 is not divisible by 3.
You may assume the number is a nonnegative integer.
Sample Run #1: (the highlighted text is what the user types)
Number? 1234
Sum = 10
1234 is NOT divisible by 3
Sample Run #2: (the highlighted text is what the user types)
Number? 123
Sum = 6
123 is divisible by 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!