Saturday 3 January 2015

Cpp Program to check whether a number is Palindrome number or not



This is a Cpp program which checks whether a number is palindrome or not .
Generally a number is said to be a palindrome number if its reverse is same as the original number .

For Example : 121 is a palindrome as its reverse is also 121 where as , 231 is not a palindrome as its reverse is 132 .


PROGRAM :


#include <iostream>

using namespace std;

int main()
{
    int n,copy_num,remainder,reverse = 0;
    cout << "Enter a number : \t" ;
    cin >> n;
    copy_num = n;

    while(n)
    {
        remainder = n%10;
        reverse = reverse*10+remainder;
        n=n/10;
    }
    if(reverse == copy_num)
        cout << copy_num <<" is a PALINDROME "<< endl;
    else
        cout << copy_num << "  is not a palindrome " << endl;
    return 0;
}

OUTPUT :