in C:
int reverseint(int x) {
int y, k=1;
while ( x > 10 ) {
y = k * ( x % 10 );
k *= 10;
x /= 10;
}
return y;
}
Anónimo
3 oct 2011
whoops!
"int y" should be "int y=0" and "y = k * ( x%10 )" should be "y += k * (x%10)"
Anónimo
17 ene 2013
num = 0
for (i=0; i
Anónimo
17 ene 2013
Sorry the for loop goes from last to 0. And we decrement "i"
Anónimo
17 ene 2013
A simple code example. Here the number to be reversed is 621.
#include
int main()
{
int y=0, k=1, x=621;
int a;
while ( x > 1 )
{
a = ( x % 10 );
y = y *10 + a;
x /= 10;
}
printf ("%d", y);
return 0;
}
And the output will be 126.