Reverse A Number C Program

C Program To Reverse a Number using Loops

Learn How To Reverse A Number in C Programming Language. It is important that we should know How A For Loop Works before getting further with this C Program Code.


To Reverse the Digits of an Integer, we need to Extract every End Digit using Modulus Operator and then store it in a Sum variable. Then, keep on adding the other digits to the Sum variable.

Example

Reverse of 1234 = 4321

Method 1: Reverse an Integer with While Loop in C Programming

Method 2: Reverse a Number using For Loop in C Programming

Method 3: C Program Code To Reverse a Number using Function

Method 4: C Code To Reverse an Integer using Recursion


Output

Learn How To Reverse A Number in C Programming Language

In case you get any Compilation Errors with this C Program To Reverse the Digits of a Number or you have any doubt about it, mention it in the Comment Section.

Recommended Programs
C Program To Find Sum of First Natural Numbers
Print Hello World without using Semicolon in C Programming Language
C Program To Search The Smallest Digit in a Number
Find Arithmetic Progression in C Programming
C Program To Convert Hexadecimal Value To Binary Value
C Program To Find Armstrong Number

Tushar Soni

I am Tushar Soni, Co - Founder of CodingAlpha. I am a computer science student from India and passionate about Web Development and Programming. Connect with me on Facebook | LinkedIn | Google Plus

10 thoughts on “Reverse A Number C Program

  • July 21, 2016 at 2:43 pm
    Permalink

    how can I display reverse of 100,200,2000…etc as 001,002,0002…/etc

    is there any code for it

    Reply
  • July 31, 2016 at 10:05 pm
    Permalink

    I think the same method will work fine to display reverse of 100, 200 and such numbers.

    Reply
  • August 20, 2016 at 4:13 pm
    Permalink

    Thanks for so many methods. This has helped me to.understand the difference between while loop and for loop so efficiently. Reverse Number C Program is also used as a parr of Palindrome Number if I am not wrong.

    Reply
  • August 20, 2016 at 4:14 pm
    Permalink

    Is there any library function to reverse an integer in C Programming? It would be then so easy.

    Reply
    • September 5, 2016 at 12:19 pm
      Permalink

      For Reversing a String, there is a function strrev(). I am not sure about Reversing Function for Integers. However, you can check the above function. Copy it into a new header file and include it in your program.

      Reply
  • September 8, 2016 at 1:39 pm
    Permalink

    This is fucking amazing man! So many methods just to reverse an integer?? Thanks!!! 🙂

    Reply
  • September 13, 2016 at 10:17 pm
    Permalink

    For (; num>0; num = num/10)
    This is something that I found. I guess it meams that we can skip a part of the For loop without getting amh compilation error.

    Reply
  • September 13, 2016 at 11:03 pm
    Permalink

    Thank you so much for the explanation of how to reverse a number in c programming.

    Reply
  • October 14, 2016 at 9:49 am
    Permalink

    In your second method to reverse an integer, the for loop can be modified to represent a normal for loop in the following way:
    for(temp = num; num > 0; num = num/10;)
    {
    rem = num%10;
    sum = (sum*10) + rem;
    }

    Reply
  • February 15, 2017 at 4:57 pm
    Permalink

    If I give 123 they answer will be 321 & 432 will be show means what codes be use ?

    Reply

Join The Discussion