Thread: How to return reverse number in function

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    99

    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. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Yes, it is possible. Warning when reversing numbers they could exceed the size that fits in the integer type of the input.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    99
    Quote Originally Posted by stahta01 View Post
    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. #4
    Registered User
    Join Date
    Jun 2017
    Posts
    157
    Google will tell you: LMGTFY

  5. #5
    Registered User
    Join Date
    Jan 2018
    Posts
    1


    you can reverae a number
    Code:
     
    while
    Code:
    (n !=0)
        {
            remainder = n%10;
            reversedNumber = reversedNumber * 10+ remainder;
            n /=10;
        }
    

  6. #6
    Registered User
    Join Date
    Apr 2012
    Posts
    99
    @shwetakakran @OldGuy2

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

  7. #7
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    941
    Quote Originally Posted by vead View Post
    @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. #8
    Registered User
    Join Date
    Apr 2012
    Posts
    99
    Quote Originally Posted by christop View Post
    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. #9
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Functions in C - Cprogramming.com

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

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  10. #10
    Registered User
    Join Date
    Apr 2012
    Posts
    99
    Quote Originally Posted by stahta01 View Post
    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. #11
    Registered User
    Join Date
    Jun 2017
    Posts
    157
    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. #12
    Registered User
    Join Date
    Dec 2017
    Posts
    1,626
    Quote Originally Posted by stahta01 View Post
    I am guessing the OP has no idea of how to write an function.
    I fear the problem is much deeper.
    A little inaccuracy saves tons of explanation. - H.H. Munro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 29
    Last Post: 10-24-2014, 02:36 PM
  2. return decimal number back caller function
    By andy09 in forum C Programming
    Replies: 7
    Last Post: 10-10-2009, 08:10 AM
  3. Replies: 10
    Last Post: 09-27-2005, 12:49 PM
  4. A function to reverse a string and return it...
    By Nutshell in forum C Programming
    Replies: 18
    Last Post: 01-11-2002, 11:19 PM

Tags for this Thread