palindromic number | Sololearn: Learn to code for FREE!

-5

palindromic number

A palindromic number is a number (such as 626) that remains the same when its digits are reversed. Write a function that returns true if a given number is a palindrome, and false, if it is not. Complete the given function, so that the code in main works and results in the expected output. Sample Input: 13431 Sample Output: 13431 is a palindrome

1/30/2021 9:03:49 PM

Hazem_Alfayyad

19 Answers

New Answer

+7

hamza mafad You can convert the input to string and reverse that string, then check if the reversed value is equal to the original one. That's one way to solve it. That's what code coach is about, for you to make an effort to solve x problem

+38

#include <iostream> using namespace std; int revDigit(int y){ int rem,rev=0; while(y>0){ rem=y%10; rev=rev*10+rem; y/=10; }return rev; } bool isPalindrome(int x) { //complete the function if(x==revDigit(x)){ 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; }

+2

Well, where's your try?

+2

Thank you very much🤗❤

+2

#include <iostream> using namespace std; int revDigit(int y) { int rem,rev=0; while(y>0) { rem=y%10; rev=rev*10+rem; y/=10; }return rev; } bool isPalindrome(int x) { if(x==revDigit(x)) { 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; }

+1

Unfortunately, I did not find the solution, so I shared the problem here so that someone can guide me to the solution, but I think I will use the "string" to cut or edit.

+1

#include <iostream> //#include <conio.h> using namespace std; int main() { int Input_Num; int Orignal_Num; int Reverse_Num; int Remainder=0; cin>>Input_Num; Orignal_Num=Input_Num; //int lengthCount = 0; for(; Input_Num != 0;) { Reverse_Num=Input_Num%10; Input_Num /= 10; Remainder=Remainder*10+Reverse_Num; Reverse_Num=Remainder; } if(Orignal_Num==Reverse_Num) { cout <<Orignal_Num<<" is a palindrome"; } else { cout <<Orignal_Num<<" is NOT a palindrome"; } return 0; }

+1

#include <iostream> using namespace std; int revDigit(int y){ int rem,rev=0; while(y>0){ rem=y%10; rev=rev*10+rem; y/=10; }return rev; } bool isPalindrome(int x) { //complete the function if(x==revDigit(x)){ 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; }

0

#include <iostream> using namespace std; int revDigit(int y){ int rem,rev=0; while(y>0){ rem=y%10; rev=rev*10+rem; y/=10; }return rev; } bool isPalindrome(int x) { //complete the function if(x==revDigit(x)){ 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; }

0

hello guys your code it's doesn't works because 8888 is not palindrome but i right in number 1 and 5,6

0

#include <iostream> using namespace std; int revDigit(int y){ int rem,rev=0; while(y>0){ rem=y%10; rev=rev*10+rem; y/=10; }return rev; } bool isPalindrome(int x) { //complete the function if(x==revDigit(x)){ 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; }

0

#include <iostream> using namespace std; int revdigit(int y){ int rem, rev=0; while(y>0){ rem = y%10; rev = rev*10+rem; y = y/10; }return rev; } bool isPalindrome(int x) { //complete the function if(x==revdigit(x)){ 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; }

0

#include <iostream> using namespace std; int revdigt(int z){ int digit,rev=0; while (z > 0) { digit = z % 10; rev = (rev * 10) + digit; z = z/ 10; } return rev; } bool isPalindrome(int x) { //complete the function if (x == revdigt(x)){ 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; }

0

#include <iostream> using namespace std; int revDigit(int y){ int rem,rev=0; while(y>0){ rem=y%10; rev=rev*10+rem; y/=10; }return rev; } bool isPalindrome(int x) { //complete the function if(x==revDigit(x)){ 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; }

0

#include <iostream> using namespace std; bool isPalindrome(int x) { //complete the function int rev, val; val = x; while(x > 0){ rev = rev * 10 + x % 10; x = x / 10; } if (rev == val){ 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; } GOOGLE is your best friend in CODING!!

0

#include <iostream> using namespace std; int revDigit(int y){ int rem,rev=0; while(y>0){ rem=y%10; rev=rev*10+rem; y/=10; }return rev; } bool isPalindrome(int x) { //complete the function if(x==revDigit(x)){ 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; } Good Luck

0

Can someone explain to me how the entire code works please? This is how I understand it: starting from main() the isPalindrome(n) function is called passing the n variable (input) to that function. Then within that function does variable n become x within the isPalindrome function? Then x is compared to revDigit while also calling the revDigit function? I want to make sure I understand this correctly, Thank you!

0

#include <iostream> using namespace std; int revDigit(int y){ int rem,rev=0; while(y>0){ rem=y%10; rev=rev*10+rem; y/=10; }return rev; } bool isPalindrome(int x) { //complete the function if(x==revDigit(x)){ 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; }

-2

#include <iostream> using namespace std; int revdigit(int y){ int rem, rev=0; while(y>0){ rem = y%10; rev = rev*10+rem; y = y/10; }return rev; } bool isPalindrome(int x) { //complete the function if(x==revdigit(x)){ 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; }