C Program to Reverse a Number using Recursive Function

Write a C program to reverse a number using a recursive function. In this C example, the user-defined function accepts the integer and iterates the value recursively to reverse the given number. On each iteration, the reverse variable will collect the last digit of a number.

#include <stdio.h>

int rem, reverse = 0;

int reverse_number(int Number)
{
  if (Number > 0)
   {
     rem = Number % 10;
     reverse = reverse * 10 + rem;
     reverse_number (Number /10);
   }
   return reverse;
}
int main()
{
  int number;

  printf("Please Enter any number to Reverse = ");
  scanf("%d", &number);

  reverse = reverse_number(number);

  printf("Reverse of entered number %d = %d\n", number, reverse);
}
C Program to Reverse a Number using Recursive Function

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.