#include <iostream> using namespace std; bool isPalindrome(int x) { //complete the function } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }
1/16/2021 8:54:01 AM
PARUCHURI YASWANTH13 Answers
New AnswerPARUCHURI YASWANTH Check this and compare with your code https://code.sololearn.com/cewmk9Y1QUql/?ref=app
PARUCHURI YASWANTH I told you method should return true if original and reverse values are equal so where is this part in your code?
PARUCHURI YASWANTH And don't make different thread for same question. https://www.sololearn.com/Discuss/2667495/?ref=app
do { digit = num % 10; rev = (rev * 10) + digit; num = num / 10; } while (num != 0);
#include <iostream> using namespace std; bool isPalindrome(int reverse, int check) { //complete the function 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; }
#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; }
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message