C Program to reverse number using recursion

Simple C program to reverse number using recursion: If the number is 2345 then program will print 5432.
#include<stdio.h>
#include<math.h>
int ReverseNumber(int n,int digits)
{
 if(n==0)
 return 0;
 return (n%10)*pow(10,digits)+ReverseNumber(n/10,digits-1);
}
int main()
{
 int n=2543,digits=0;
 int num=n;
 while(n!=0)
 {
  n=n/10;
  digits++;
 }
 printf("Reverse Number = %d\n",ReverseNumber(num,digits-1));
 return 0;
}


Popular posts from this blog