reversing number problem.
i have done a simple program, which i asked..(don't know how many days ago.)
but i find that there is a problem..
if i give an input (for example) 1234
it shall reverse back 4321 (it does)
when i key in 100, by right it should return 001, but it returned as 1.
my question is how to make that two zeros in front visible. (is there any mistake(s) for my "this" program??)
#include
using namespace std;
long reverse();
int main()
{ long a;
a = reverse();
cout << "The reversed number is " << a << endl;
return 0;
}
long reverse()
{
long x, y, z = 0;
cout << "Enter an integer to be reversed: ";
cin >> x;
while (x > 0){
y = x%10;
x = x/10;
z = 10 * z + y;
}
return z;
}
thank you....
koh
Junior Poster in Training
73 posts since Jul 2004
Reputation Points: 11
Solved Threads: 0
>This program gets very easy with the use if recursive
>function if the job is only to print the number in the reverse order.
So, was it worth resurrecting a three year old thread to post some bad code?
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401