Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C++ Exercises: Check whether a given number is palindrome or not

C++ Numbers: Exercise-38 with Solution

Write a program in C++ to check whether a given number is palindrome or not.

Sample Solution:

C++ Code :

#include <iostream>
using namespace std;
int main()
{
    int i,n1,r,s=0;
 cout << "\n\n Check whether a given number is palindrome or not: \n";
 cout << " -------------------------------------------------------\n";
 	cout << " Input a number: ";
    cin>>n1;	
    for(i=n1;i>0; )
    {
        r=i % 10;
        s=s*10+r;
        i=i/10;
    }
    if(s==n1)
    {
        cout<<" "<<n1<<" is a Palindrome Number."<<endl;
    }
    else
    {
        cout<<" "<<n1<<" is a not Palindrome Number."<<endl;
    }
}

Sample Output:

Check whether a given number is palindrome or not:                    
 -------------------------------------------------------               
 Input a number: 141                                                   
 141 is a Palindrome Number.

Flowchart:

Flowchart: Check whether a given number is palindrome or not

C++ Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a program in C++ to find Narcissistic decimal numbers within a specific range.
Next: Write a program in C++ to print the first 20 numbers of the Pell series.

What is the difficulty level of this exercise?