That is a most interesting way to reverse a number.
Anyways, let me point out your mistakes.
First of all...
3 4
|
const int ARRAY_SIZE=100000000;
int integer [ARRAY_SIZE];
|
That is a MASSIVE array you're declaring there.
int
can't even store close to 100 million digits, so why declare an array that big? (10 digits is sufficient)
25 26
|
int A, count, i=0;
for (count=10; A>9; count*=10)
|
A is being used uninitialized here.
Give it some initial value greater than 9.
35 36 37 38 39
|
while (i>=0)
{
cout << integer [i];
i--;
}
|
When you first enter this
while
loop,
i is 1 greater than it should be. (because you incremented i right before you exited the loop above this)
That's where the first 0 came from. (you're lucky it was 0 and not something like 4214816, or else you would've gotten the output 42148163210)
The last 0 comes from the fact that you're displaying the reversed number in your
reverseDigits function, and then back in
main(), you're displaying the value that
reverseDigits returned. (which just happened to be 0, because you didn't write any
return
statement at the end of your
reverseDigits function).
Hope this makes sense....