Reverse number without recursion in Python

  

         Reverse number  in Python 

Python program to reverse a number and to print it on the screen. For example, if the input is 123, the output will be 321

Reverse number  without recursion  in Python

Program:

reverse=0; rem=0;    
n=int(input("Enter a number: "))       
while(n!=0):    
     rem=n%10;    
     reverse=reverse*10+rem;    
     n//=10;      
print("Reversed Number: ",reverse);    



OutPut:
Enter a number: 123
Reversed Number:  321

Enter a number: 257
Reversed Number:  752








No comments:

Post a Comment