C Program to Reverse a Number Using Recursion

C Program to reverse a number using recursion. In this program, we can reverse a number using recursion for beginners to understand programming concepts in c.

Recursion Definition in C

When a function calls a copy of itself to work on a smaller problem, the process is known as recursion. 

A recursive function is one that calls itself, and such function calls are referred to as recursive calls. 

A process in which a function calls itself a subroutine is known as recursion. 

Because the function calls itself during execution, it can be repeated multiple times. 

Recursive functions are functions that incorporate recursion.

If Else Statement in C

If the condition is true, the statements in the “if” body are executed, while the statements in the “else” body are skipped. 

If the condition is false, the statements in the body of the “if” are skipped and the statements in “else” are executed. 

The if statement is a decision-making structure that consists of one or more statements following an expression. 

The if-else structure is a decision-making structure in which the if statement is followed by an optional else statement that runs when the expression is false.

C Program to Reverse a Number Using Recursion

#include<stdio.h>
int main()
{
int num,func;
printf("Enter The Number");
scanf("%d",&num);
func=reversed(num);
printf("\nAfter Reversed%d",func);
return 0;
}
int sum=0,rem;
reversed(int num)
{
if(num)
{
rem=num%10;
sum=sum*10+rem;
reversed(num/10);
}
else
return sum;
return sum;
}

Output:

Enter The Number 45

After Reversed 54