Dremendo Tag Line

Input a number and check it is a palindrome number or not using while loop in C++

while Loop - Question 14

In this question, we will see how to input a number and check if it is a palindrome number or not in C++ programming using while loop. To know more about while loop click on the while loop lesson.

Q14) Write a program in C++ to input a number and check if it is a palindrome number or not using while loop.

Palindrome numbers are such numbers whose reverse is same as the original number. Example, 121, 14541, 22 etc.

Program

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    int n,d,on,rev=0;

    cout<<"Enter any number ";
    cin>>n;
    on=n;			// storing the original number

    while(n>0)
    {
        d=n%10;
        rev=(rev*10)+d;		// reverse the number
        n=n/10;
    }

    if(on==rev)
    {
        cout<<"Palindrome Number";
    }
    else
    {
        cout<<"Not Palindrome Number";
    }
    return 0;
}

Output

Enter any number 14541
Palindrome Number
video-poster