Write a program in c++ to input a number and check if it is palindrome or not

   

Write a program  in c++ to input a number and check if it is  palindrome or not

Palindrome : palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam or racecar.

#include <iostream>
using namespace std;
int main()
{
    int nnumldigitrev = 0;
    cout << "Enter a Number : ";
    cin >> n;
    num = n;
    while (num != 0)
    {
        ldigit = num % 10;
        rev = rev * 10 + ldigit;
        num /= 10;
    }
    if (rev == n)
    {
        cout << n << " is palindrome";
    }
    else
        cout << n << " is not palindrome";
}

OUTPUT

1. 
     Enter a Number : 123454321
     123454321 is palindrome

2. 
     Enter a Number : 345232
     345232 is not palindrome



Share:

0 Comments:

Post a Comment

Pageviews