# Find reverse of a number using recursion

Write a C program to find the reverse of a number using recursion. or Write a program to find the reverse of a number using recursion in C.

Program in C

Code:

#include <stdio.h>
void reverse(int number)
{
if (number < 10)
{
printf("%d",number);
return;
}
else
{
printf("%d",number % 10);

reverse(number/10);
}
}
int main()
{
int num;
scanf("%d",&num);
printf("Reverse of the input number is:\n ");
reverse(num);
}

Input/Output:
Reverse of the input number is:
4052

Write a C++ program to find the reverse of a number using recursion. or Write a program to Calculate Reverse a number using Recursion in C++.

Program in C++

Code:

#include<iostream>
using namespace std;
void reverse(int number)
{
if (number < 10)
{
cout<<number;
return;
}
else
{
cout<<number % 10;

reverse(number/10);
}
}
int main()
{
int num;
cin>>num;
cout<<"Reverse of the input number is:  ";
reverse(num);
}

Input/Output:
78456
Reverse of the input number is:  65487

Write a JAVA program to Calculate Reverse a number using Recursion. or Write a program to Calculate Reverse a number using Recursion in Java.

Program in Java

Code:

import java.util.Scanner;
public class ReverseNumberRecursion {
public static void reverse(int number) {
if (number < 10)
{
System.out.println(number);
return;
}
else
{
System.out.print(number % 10);

reverse(number/10);
}
}
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int num;
Scanner in = new Scanner(System.in);
num = in.nextInt();
System.out.print("Reverse of the input number is:");
reverse(num);
cs.close();
}
}

Input/Output:
3655
Reverse of the input number is:5563

Write a PYTHON to Calculate Reverse a number using Recursion. or Write a program to Calculate Reverse a number using Recursion in Python.

Program in Python

Code:

def reverse(num):
if num<10:
print(num)
return
else:
print(num % 10,end="")
reverse(int(num / 10))