#number digit
13 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
that could work yes
how?
Welcome to Together C & C++ :wave:
We won't do your homework for you (#rules) but we are happy to help you learn and point you in the right direction.
Please send what you have so far and ask a specific question.
Can you show your attempt as code, and tell us what problems you have with it?
to get the first (most significant) digit, you can repeatedly divide by 10 until the result is < 10 or you could divide n by 10^number-of-digits-in-n-minus-1. The number of digits minus one can be obtained from log10 of that number, or you could just read one character at a time left to right. Give it some thought...
But... Wouldn't that just always result in you getting a 1-digit number after the very first iteration?
Because if you have e.g. 123456789 and you decide to grab first (1) and last digit (9) and you subtract them, then you get |1 - 9| = |-8| = 8 (assuming you want the absolute value).
What do you do then? Just do |8 - 8| in the next iteration because 8 was the first and last digit of the number 8?
Also why would you want to loop? Like, this is guaranteed to be 2 iterations at max.
If you're really (un-)lucky you could end up with only 1 iteration even, e.g. if your number is 4xxxxxxxxxxxx4, then you'd do |4 - 4| = 0 in the first iteration, meaning you're already finished.
Or ofc if your input number is 0 to begin with, then you're immediately finished
But I can't see any other scenario than 0, 1 or 2 iterations
yeah
i guessed it was subtracting 8 from 123456789
idk