Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- bool isPalindrome( int );// Prototype for this function.
- bool isPalindrome( int num ) {
- int number, last, sum = 0;// Initialize some variables.
- for ( number = num; num != 0; num /= 10 ) {// While integers are still in the sequence...
- last = num % 10;// The last number in the sequence.
- sum = sum * 10 + last;// Add the current last digit to a new sequence that reverses the original number.
- }
- if ( number != sum )// If the original number is not equal to the reversed number...
- return false;// ... then it is not a palindrome since numbers don't match.
- return true;// The integer survived the tests and proved itself as a palindrome.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement