Write a program to find the reverse of n digit number using While loop


This program is a simple program that takes an input number from the user and then reverses the number. It first takes the input number and assigns it to the variable 'num'. Then it initializes a variable 'sum' to 0. The program enters a while loop where it takes the remainder of the input number when divided by 10 and assigns it to the variable 'rem'. The variable 'sum' is then updated with the product of its current value and 10, and the remainder obtained from the previous step is added to it. The input number is then updated to its quotient when divided by 10. The while loop continues to execute until the input number becomes 0. After the while loop, the program prints the original number and the reversed number obtained from the above process.

Source Code

num = int(input("Enter the Number :"))
a=num
sum=0
while(num>0):
	rem=num%10
	sum=(sum*10)+rem
	num=num//10
print("Before Number :",a)
print("Reverse Number :",sum)

Output

Enter the Number :537458
Before Number : 537458
Reverse Number : 854735


Example Programs