CS Important Question
Q. Write a program to find palindrome of a given number.
Answer →
Logic:
Number given=158
palindrome=158+851=1009
1009+9001=10010
10010+01001=110011
Code:
n=int(input('Enter any number:'))
while True:
sn=str(n)
rev=sn[::-1]
if sn==rev:
print(n,'is palindrome')
break
else:
n=int(sn)+int(rev)
Comments
Post a Comment