 Who has answer on Palindrome numbers on c++ please help me | Sololearn: Learn to code for FREE!

-5

-3

try to change the number to string and check if the string is symmetrical like num == num[n-1], num == num[n-2] and so on ....

+4

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

+3

/*Hi! I have made an easy one with explanation! Here it is:*/ #include <iostream> using namespace std; int main() { int a; cin>>a; int b=a; int c=a; while (a>9||0) { /*separates the last digit*/ a=a%10; } while (b>9||0) { /*separates the first digit*/ b=b/10; } if (a==b) { /*compares them if they are equal or not*/ cout<<c<<" is a palindrome"<<endl; } else { cout<<c<<" is NOT a palindrome"<<endl; } } /*and if they are equal it prints that the number is a palindrome, if not then it prints that the number is NOT a palindrome*/ /*Don't change anything if you don't know how it works and if you want it to run properly.*/

0

0

#include <iostream> using namespace std; bool isPalindrome(int x) { //complete the function int n,s=0,r; x=n; while(n!=0) { r=n%10; s=s*10+r; n=n/10; } } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }

0

Try this out #include<bits/stdc++.h> using namespace std; int main() { int n, reversedInteger = 0, remainder, originalInteger; cin>>n; originalInteger = n; while( n!=0 ) { remainder = n%10; reversedInteger = reversedInteger*10 + remainder; n /= 10; } // palindrome if orignalInteger and reversedInteger are equal if (originalInteger == reversedInteger) cout<<originalInteger<<" is a palindrome"; else cout<<originalInteger<<" is NOT a palindrome"; return 0; }

0

https://code.sololearn.com/c1oRAynujss3/?ref=app

0

#include <iostream> using namespace std; bool isPalindrome(int reverse, int check) { bool status = true; if (reverse != check) { status = false; } return status; } int main() { int n, reverse = 0, rem; cin >> n; int check = n; while(n != 0){ rem = n % 10; reverse = reverse * 10 + rem; n /= 10; } if(isPalindrome(reverse, check) == 1) { cout << reverse <<" is a palindrome"; } else { cout << check <<" is NOT a palindrome"; } return 0; }

-11

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