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
12 Respostas
+ 1
What input failed? give me some failing sample for testing. I tested with "abba" and it says it is palindrome.
+ 1
Yes, it works for me too. Which Error message?
+ 1
Is a number like 010 a palindrome ?
Your program says yes, but I don't think it is.
0
Shaik Shahir,
What input did you give that didn't work? I want to test with that input to verify.
0
When the test cases are running.it gives me the failure in test case 3 and 5
0
I can't help you when it comes to hidden test cases unfortunately ÂŻ\_(ă)_/ÂŻ
0
But tese case 2 is also not working properly
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.
0
I am getting same output that supposed to outputs
But still getting the failure in test case 2
0
Let me post my code
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;
}
0
It 8s working. The input WAS a palindrome