Skip to content

Instantly share code, notes, and snippets.

@Abiola-Farounbi
Created June 14, 2021 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Abiola-Farounbi/e4385a3b398e15c024e288726d771609 to your computer and use it in GitHub Desktop.
Save Abiola-Farounbi/e4385a3b398e15c024e288726d771609 to your computer and use it in GitHub Desktop.
This problems set determines where a number is palindrome or not in c++
#include <iostream>
using namespace std;
bool isPalindrome(int x) {
//complete the function
int n, num, digit, rev = 0;
bool True = true;
bool False = false;
num = x;
do
{
// Finds the last digit number
digit = num % 10;
// Adds it to a new string in terms of the placement
rev = (rev * 10) + digit;
// removes the last digit number
num = num / 10;
} while (num != 0);
if (x == rev)
return True;
else
return False;
}
int main() {
int n;
cin >>n;
if(isPalindrome(n)) {
cout <<n<<" is a palindrome";
}
else {
cout << n<<" is NOT a palindrome";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment