Title: Reverse the given number
234 reverse number is 432
n%10= last digit of the number
n/10=last before digits
For example
234%10=4 [0*10+4=4]
234/10=23
23%10=3 [4*10+3=43]
23/10=2
2%10=2 [43*10+2=432]
2/10=0
Program:
n=int(input("Enter n value\n"))
r=0
t=n
while(t>0):
r=(r*10)+(t%10)
t=t//10
print("The reverse of ",n," is ",r)
Output:
Enter n value
234
The reverse of
234 is 432
Comments
Post a Comment