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

10 thoughts on “Reverse A Number C Program

  1. Gokul

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

    is there any code for it

    Reply
  2. Venkatesh

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

    Reply
  3. Ajay Sawant

    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
  4. Vishwajeet Patil

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

    Reply
    1. Tushar Soni Post author

      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
  5. Daniel Craig

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

    Reply
  6. Aarav Rathod

    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
  7. Mayur Sojitra

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

    Reply
  8. Hanish Ratra

    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
  9. Anonymous

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

    Reply

Let's Discuss