0

I want to know new ways to do it, this is my solution.

arr[nccard - i] = (long long)(ccard / pow(10, i - 1)) % 10;

2

You can use a loop. As long as the number is not zero, process its last digit (%10), for example storing it in an array, then divide the number by 10, shifting decimal digits to the right. If you intend to use the original number later, operate on a copy of the number instead, as this process is destructive.

That's much more efficient than using floating-point power function and converting back to long long int.

Another way could be to read a string instead of numbers, and process the digit characters, subtracting '0' from each of them.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .