0

Why doesn't it working properly??

#include <iostream> #include<string.h> using namespace std; int main() { string a; cin >> a; string b = ""; int x = a.size(); int y = x-1; for(int i = y;i >= 0;i--) { b = b+a[i]; } if(a==b) { cout << a << " is a palindrome"; } else { cout << a << " is Not a palindrome"; } return 0; } Here is the question: 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

6th Jul 2021, 3:06 PM
Shahir
Shahir - avatar
12 Respostas
+ 1
What input failed? give me some failing sample for testing. I tested with "abba" and it says it is palindrome.
6th Jul 2021, 3:09 PM
Ipang
+ 1
Yes, it works for me too. Which Error message?
6th Jul 2021, 3:13 PM
Maksat Ramazanov
Maksat Ramazanov - avatar
+ 1
Is a number like 010 a palindrome ? Your program says yes, but I don't think it is.
6th Jul 2021, 3:47 PM
Arsenic
Arsenic - avatar
0
Shaik Shahir, What input did you give that didn't work? I want to test with that input to verify.
6th Jul 2021, 3:22 PM
Ipang
0
When the test cases are running.it gives me the failure in test case 3 and 5
6th Jul 2021, 3:25 PM
Shahir
Shahir - avatar
0
I can't help you when it comes to hidden test cases unfortunately ¯\_(ツ)_/¯
6th Jul 2021, 3:26 PM
Ipang
0
But tese case 2 is also not working properly
6th Jul 2021, 3:27 PM
Shahir
Shahir - avatar
0
I can only suggest you to read thoroughly, and follow the instruction as is. Your code doesn't follow the instruction (complete given function). And also avoid printing outputs other than what was in the instruction, or output something not *exactly* as is given in the instruction. This can be extra space, unnecessary punctuation, or letter case mismatch etc.
6th Jul 2021, 3:36 PM
Ipang
0
I am getting same output that supposed to outputs But still getting the failure in test case 2
6th Jul 2021, 3:44 PM
Shahir
Shahir - avatar
0
Let me post my code
7th Jul 2021, 10:44 PM
Ronald Gavuna
Ronald Gavuna - avatar
0
#include <iostream> using namespace std; bool isPalindrome(int x) { //complete the function int rev=0; int r; int rev1=x; while(x!=0) { r=x%10; rev=(rev*10)+r; x=x/10; } if(rev==rev1) { return 1; } else { return 0; } } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }
7th Jul 2021, 10:45 PM
Ronald Gavuna
Ronald Gavuna - avatar
0
It 8s working. The input WAS a palindrome
8th Jul 2021, 10:32 AM
Chin Serng Siew
Chin Serng Siew - avatar