programming-examples/c/Recursion/C Program to Reverse a number using recursion.c
2019-11-15 12:59:38 +01:00

26 lines
461 B
C

#include<stdio.h>
int main()
{
int num,reverse;
printf("Enter any number: ");
scanf("%d",&num);
reverse=rev(num);
printf("Reverse of number: %d",reverse);
return 0;
}
int rev(int num)
{
static sum,r;
if(num)
{
r=num%10;
sum=sum*10+r;
rev(num/10);
}
else
return 0;
return sum;
}
Sample output:
Enter any number: 784
Reverse of number: 48