Reverse A Number C Program

By | September 18, 2015

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.


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


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

15 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

  2. Venkatesh

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

  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.

  4. Vishwajeet Patil

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

    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.

  5. Daniel Craig

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

  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.

  7. Mayur Sojitra

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

  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;

  9. Anonymous

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

  10. Keshav Prasad

    How to return a reversed number from helper function to main function without using array.

  11. tfk

    //this is how you reverse it without loops

    int main(){
    int num;
    printf(“enter a 4 digits number\n”);
    int a=num/1000;
    int rest1=num%1000;
    int b= rest1/100;
    int rest2=rest1%100;
    int c=rest2/10;
    int rest3=rest1%10;
    int d=rest3;
    int mun=(d*1000)+(c*100)+(b*10)+a;
    printf(“the reverse of your number is %d”,mun);
    return 0;

  12. Ankush Batra

    we can’t reverse “001” by any of these methods…………


Let's Discuss