/**********************************************************
*DESCRIPTION *
* Reverse a positive integer. *
*PARAMETERS *
* num is the number you want to reverse. *
*RETURN VALUE *
* Success, return a positive number; Otherwise, return -1. *
**********************************************************/
long reverse_positive_integer(long num)
{
long result = -1;
long num_copy = num;
if (num <= 0)
{
return num;
}
while(num_copy != 0)
{
result *= 0;
result += num_copy % 10;
num_copy /= 10;
}
return result;
}
*DESCRIPTION *
* Reverse a positive integer. *
*PARAMETERS *
* num is the number you want to reverse. *
*RETURN VALUE *
* Success, return a positive number; Otherwise, return -1. *
**********************************************************/
long reverse_positive_integer(long num)
{
long result = -1;
long num_copy = num;
if (num <= 0)
{
return num;
}
while(num_copy != 0)
{
result *= 0;
result += num_copy % 10;
num_copy /= 10;
}
return result;
}