Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

=+Could you create an interactive game on the website?

Answered: 1 week ago