Skip to main content

Computer Science | Class 11 CBSE | 2021-22 Session

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

Popular posts from this blog