Home » Reversing a Number in C

Reversing a Number in C

Learn about Reversing a Number in C in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.


Reversing a Number in C:

For Reversing a number each element from last should be obtained and add in new number.Palindrome number is checked using this reversing digit and comparing. Here is the example of Reversing a Number in c.

#include <stdio.h>
int main() 
    int r,rev,n;
    printf("Enter number:");
        r=n%10;//obtain last digit   
        rev=(rev*10)+r;//Add to new digit  
        n=n/10;//removing last digit in given number   

Enter number:1564

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Also Read:

Fibonacci Number in C check whether a number is palindrome or not in C