C Program to Reverse a Number using Recursive Function

Write a C program to reverse a number using recursive function. In this c example, the reverse_number function accepts the integer and iterates the number 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