Reverse of a number using recursion in python
reverseNumber = 0
def reverse(num):
global reverseNumber
if (num > 0):
Reminder = num % 10
reverseNumber = (reverseNumber * 10) + Reminder
reverse(num // 10)
return reverseNumber
number=int(input("Input the number: "))
res = reverse(number);
print(f"Reverse of {number} is {res}.");
Comments
Leave a comment