# Thread: How to return reverse number in function

1. ## How to return reverse number in function

Is it possible to get reverse number in return ?

If i pass number 123 then I want the function which can give the reverse number of original number
Code:
int main ()
{
return 0;
}

unsigned int reverse (unsigned int number)
{
}
it will be like this

321 reverse (123)

Is it possible ?

2. Yes, it is possible. Warning when reversing numbers they could exceed the size that fits in the integer type of the input.

Tim S.

3. Originally Posted by stahta01
Yes, it is possible. Warning when reversing numbers they could exceed the size that fits in the integer type of the input.

Tim S.
Actually I don't have any idea how to do it

4. Google will tell you: LMGTFY

5. you can reverae a number
Code:

while
Code:
(n !=0)
{
remainder = n%10;
reversedNumber = reversedNumber * 10+ remainder;
n /=10;
}

6. @shwetakakran @OldGuy2

I don't wan't to do it with modulo operators

@shwetakakran @OldGuy2I don't wan't to do it with modulo operators
Why not? Is this some sort of homework assignment in which you're forbidden from using the modulus operator?

8. Originally Posted by christop
Why not? Is this some sort of homework assignment in which you're forbidden from using the modulus operator?
I am thinking in this way because I think it's easy we can pass number and can get return number in function. I know we can do it with modulus operator and I have done it before

9. Functions in C - Cprogramming.com

I am guessing the OP has no idea of how to write an function.

Tim S.

10. Originally Posted by stahta01
Functions in C - Cprogramming.com

I am guessing the OP has no idea of how to write an function.

Tim S.
program
Code:
#include<stdio.h>
int reverse(int number, int returnNumber);
int main()
{
int reverseNumber;

reverseNumber = reverse(123,321);
printf("\n reverse Number %d",reverseNumber);

return(0);
}
int reverse(int number, int returnNumber)
{
returnNumber = 321;
return(returnNumber);
}
Reverse number is = 4926

11. If you don't want to use the modulo operator convert the number to a string, reverse the string and convert it back to a number.

12. Originally Posted by stahta01
I am guessing the OP has no idea of how to write an function.
I fear the problem is much deeper.