C++ to enter any number and check whether the given number is palindrome or not.

Thiru Malai
Jun 5, 2021

Palindrome

A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward.

In the below program, user is asked to enter a positive number which is stored in the variable num.

The number is then saved into another variable n to check whether the original number has been reversed.

In the while loop, last digit of the number is seperated using the code digit=num%10.

Before adding the digit to rev, we first need to multiply the current data in the rev variable by 10 in order to add the digit to the last place in the number.

When the numbers are equal, the original number is a palindrome, otherwise it’s not.

Coding:

Output:

Reference:

--

--