In the following example, we will check whether the given number (121) is a Palindrome number or not.
Example
C++ Compiler
#include<iostream>using namespace std;
int main()
{
int num =121;
int copyNum = num;
int reverse =0;
// reverse a numberwhile(copyNum !=0)
{
reverse = reverse *10;
reverse = reverse + (copyNum %10);
copyNum = copyNum /10;
}
// resultif(num == reverse)
cout << num <<" is a palindrome number";
else
cout << num <<" is not a palindrome number";
return0;
}
In the following example, we will find all the Palindrome numbers between 10 and 50.
Example
C++ Compiler
#include<iostream>using namespace std;
int main()
{
int start =10;
int end =50;
int copyNum =0;
int reverse =0;
int flag =0;
cout <<"Palindrome numbers between "<< start <<" and "<< end <<":\n";
for(start=start; start<=end; start++)
{
copyNum = start;
reverse =0;
// reverse a numberwhile(copyNum !=0)
{
reverse = reverse *10;
reverse = reverse + (copyNum %10);
copyNum = copyNum /10;
}
// resultif((start == reverse) && (start !=0))
{
flag =1;
cout << start <<" ";
}
}
if(flag ==0)
cout <<"There is no palindrome number between the given range";
return0;
}