C Program to Reverse Number using Recursion

C Program to Reverse Number using Recursion

Write a Program to Reverse Number using Recursion

// C Program to Reverse Number using Recursion

#include <stdio.h>

int reverse_number(int n)
{
	static long int ans = 0;
	if(n <= 0)
	{
		return ans;
	}
	int remainder = n % 10;
	ans = ans * 10 + remainder;

	reverse_number(n / 10);

	return ans;

}

long int main()
{
	long int n;
	printf("Enter Number :--> ");
	scanf("%ld", &n);

	printf("Reverse of %ld = %ld", n, reverse_number(n));

	return 0;
}

Output:

Enter Number :--> 123456
Reverse of 123456 = 654321