-
May 19th, 2022, 01:06 AM
#1
Palindrome Problem in C++
hello Everyone, I'm trying to write a C++ program to find if palindrome number. Here's my code. The problem is that the program returns false even when the number is a palindrome. For example, the number 12321 is a palindrome number, but 1451 is not a palindrome number.
Code:
bool checkPalindrome(int original) {
int reverseNum = 0;
int tempOriginal = original;
while (tempOriginal > 0) {
int lastDigit = tempOriginal % 10;
reverseNum = reverseNum * 10 + lastDigit;
tempOriginal = tempOriginal / 10;
}
if (original == reverseNum) {
return true;
} else {
return false;
}
}
I have taken this code reference from this post. Can anyone tell me, Is this logic right?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|