Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started