Define the Function for checking Palindrome Number
In this step, we will define the function for checking whether the number is Palindrome or not.
void check_palindrome(int a){
int temp=a;
int res=0;
for(int i=a;i>0;i=i/10){
res+=res*10+i%10;
}
if(temp==res){
cout<<a<<" is a Palindrome number";
}
else{
cout<<a<<" is not a Palindrome number";
}
}
Code Explanation:
We have defined a function check_palindrome
that takes an integer value as a parameter.
We have defined two integer variables for holding the number. The variable temp
contains the input number, and the variable res
holds the reverse of the input number.
We have used a loop to reverse the number.
We have compared the temp
number and res
number and displayed the corresponding message.