Program to Check Whether a Number is Palindrome or Not.

A palindromic number or numeral palindrome is a number that remains the same when its digits are reversed. Like 16461, for example, it is "symmetrical". The term palindromic is derived from palindrome, which refers to a word (such as rotor or LOL) whose spelling is unchanged when its letters are reversed.

This program reverses an integer entered by the user using while loop. Then, if statement is used to check whether the reversed number is equal to the original number or not.

Program:-

#include <iostream.h>
#include<conio.h>
void main()
{
clrscr();
     int n, num, digit, rev = 0;
     cout << "Enter a positive number: ";
     cin >> num;
     n = num;
     do
     {
         digit = num % 10;
         rev = (rev * 10) + digit;
         num = num / 10;
     } while (num != 0);

     cout << " The reverse of the number is: " << rev << endl;

     if (n == rev)
         cout << " The number is a palindrome";
     else
         cout << " The number is not a palindrome";
getch();
}
Output:-
Program to Check Whether a Number is Palindrome or Not.

Post a Comment

0 Comments