Computer Science, asked by mdnizamulkhan5152, 3 months ago

Write a program to read an integer number and print whether the number is a palindrome.( For

ex- 121 is a palindrome)​

Answers

Answered by anindyaadhikari13
3

Answer:

This is the required program for the question in python.

1. Using numeric approach.

n=int(input("Enter a number: "))

m,s=n,0

while m!=0:

s=s*10+m%10

m//=10

if s==n:

print("Palindrome.")

else:

print("Not Palindrome.")

Using numeric approach, we will reverse the number and check if the reversed number is equal to the original number or not. If true, the number is palindrome else not.

2. Using string approach.

n=int(input("Enter a number: "))

s=str(n)

if s==s[::-1]:

print("Palindrome.")

else:

print("Not Palindrome.")

Using string approach, we will convert the number to string and then check if the string and the reversed string are equal or not.

Here, n is converted to string and is stored in s. s[::-1] returns the reverse of s. So, if s is equal to s[::-1], the string is palindrome else not.

See the attachment for output .

Attachments:
Similar questions