Problem statement
Check whether a given number ānā is a palindrome number.
Example:
Input: 'n' = 51415
Output: true
Explanation: On reversing, 51415 gives 51415.
Checking for Palindrome Numbers
Palindrome numbers are numbers that read the same backward as forward. For example, 121 and 12321 are palindrome numbers. To check if a number is a palindrome, we can reverse the number and compare it with the original number. If they are the same, the number is a palindrome; otherwise, it is not. Using the concepts of extracting digits and reversing a number, we can efficiently check for palindrome numbers.
bool palindrome(int n)
{
// Write your code here
int num=0,temp;
for(int i=n; i>0;i=i/10)
{
temp=i%10;
num=(num*10)+temp;
}
if(num==n)
return true;
else
return false;
}
Comments
Post a Comment