+1 vote
in Python by
Write a python program to check if the number given is a palindrome or not

1 Answer

0 votes
by

Below is the code to Check whether the given number is palindrome or not:

We will start off by taking an input and store it in ‘n’ and make a duplicate of it in ‘temp’. We will also initialize another variable ‘rev’ to 0. 

Then, we will enter a while loop which will go on until ‘n’ becomes 0. 

Inside the loop, we will start off by dividing ‘n’ with 10 and then store the remainder in ‘dig’.

Then, we will multiply ‘rev’ with 10 and then add ‘dig’ to it. This result will be stored back in ‘rev’.

Going ahead, we will divide ‘n’ by 10 and store the result back in ‘n’

Once the for loop ends, we will compare the values of ‘rev’ and ‘temp’. If they are equal, we will print ‘The number is a palindrome’, else we will print ‘The number isn’t a palindrome’.

Related questions

0 votes
asked Jan 7 in C Plus Plus by GeorgeBell
+1 vote
asked Feb 15, 2021 in Python by SakshiSharma
...