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.
Contents
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:");
scanf("%d",&n);
while(n>0)
{
r=n%10;//obtain last digit
rev=(rev*10)+r;//Add to new digit
n=n/10;//removing last digit in given number
}
printf("%d",rev);
}
Enter number:1564
4651
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