C Program to Reverse a Number Using Recursion

In this article, We are going to talk about “C Program to Reverse a Number Using Recursion”. Below, We can see the possibilities to perform this task. Let’s move.

C Program to Reverse a Number Using Recursion

C Program to Reverse a Number Using Recursion

Source Codes

#include <stdio.h>
int main()
{
  int n, r = 0;

  printf("Enter a number to reversen");
  scanf("%d", &n);

  while (n != 0)
  {
    r = r * 10;
    r = r + n%10;
    n = n/10;
  }

  printf("Reverse of the number = %dn", r);

  return 0;
}
#include <stdio.h>
long reverse(long);
 
int main()
{
   long n, r;
   
   scanf("%ld", &n);
 
   r = reverse(n);
 
   printf("%ldn", r);
 
   return 0;
}

long reverse(long n) {
   static long r = 0;
   
   if (n == 0)
      return 0;
   
   r = r * 10;
   r = r + n % 10;
   reverse(n/10);
   return r;
}

Conclusion

I hope this article helps you to know about “C Program to Reverse a Number Using Recursion“. If you face any issues please let me know via the comment section. Share this article with other C/C++ developers via social networks.

Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment