For negative numbers, you need to just take the positive value (abs value) and apply the sign separately. You don't say how you wrote the program, but it should involve either truncated division by 10 (x/10) or the modulus operator (x%10). After each digit, you'd divide by 10 and do it again until the number was zero.
No comments:
Post a Comment