on Leave a Comment

C++ Program to Check Whether a Number is Palindrome or Not

To understand C++ program to check whether a number is palindrome or not, you should know about - C++ looping.

Palindrome number in C++

If the reversed pattern of the digits of a number is equal to the original number, then the number is called palindrome number.

Note : Palindrome number must be a positive integer

C++ Program to Check Whether a Number is Palindrome or Not

#include<iostream>
using namespace std;
int main()
{
    int n,rem,rev=0,t;
    cout<<"Enter a number : ";
    cin>>n;
    t=n;
    while(n!=0)
    {
        rem=n%10;
        rev=rev*10+rem;
        n=n/10;
    }
    if(t==rev)
        cout<<endl<<t<<" is a palindrome number";
    else
        cout<<endl<<t<<" is not a palindrome number";
    return 0;
}

OUTPUT 1:

Enter a number : 45254

45254 is a palindrome number


OUTPUT 2:

Enter a number : 487

487 is not a palindrome number

0 comments:

Post a Comment