C program to reverse a number using Recursion.
A function calls itself, is called a Recursion. During the recursion, all the intermediate recursive calls data will be stored in Stack data structure. The stack works with a principle of Last in First out.
#include<stdio.h>
int main()
{
int num,x;
printf("Enter a number: ");
scanf("%d",&num);
x=rev(num);
printf("Reverse of given number is: %d",x);
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;
}
Flowchart for Reverse of a Number, the flowchart is not based on recursion, but you will get an idea about working logic to find reverse of a number.
Output for reverse of a number:
Enter a number: 4567 Reverse of given number is: 7654