how do i write a code that determines and prints the digits that make up every three-digit number
that is divisible by 47. For example, for the digit 100 the program should print:
Please read our Beginner's FAQ to learn more the culture and protocols here. One important thing to note is that we won't give out code, only tips and suggestions on how to improve your code.
Have you learned about the % operator? That's going to be a key part of the solution.
Another way is, for example, take your 457 as an input value, you can convert it to a float value (457.0) and divide by 10 (45.7).
Then convert 45.7 to a String and remove the ".", the result will be "457" (which you can split into tokens, convert each to an int, print it out, etc. as you'd like).
Marin Tapnoi wrote:Another way is, for example, take your 457 as an input value, you can convert it to a float value (457.0) and divide by 10 (45.7).
Then convert 45.7 to a String and remove the ".", the result will be "457" (which you can split into tokens, convert each to an int, print it out, etc. as you'd like).
Sorry, but that sounds a lot like Yak Shaving to me.
Junilu Lacar wrote:The recursive solution is ridiculously easy. Also, you are printing digits from left to right, which makes recursion a natural approach.
OK, I concede. Recursion however is not necessarily a beginner topic.
Marin Tapnoi wrote:. . . convert it to a float value (457.0) . . .
Avoid floats like the plague. You are risking imprecision with floating‑point arithmetic at the best of times, but floats are worse than doubles. If you really want to shave yaks, use BigDecimals. But that isn't how I would divide an int into its successive digits.