+ 1
Palindrome numbers
#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; }
14 Réponses
+ 5
PARUCHURI YASWANTH
Check this and compare with your code
https://code.sololearn.com/cewmk9Y1QUql/?ref=app
+ 3
PARUCHURI YASWANTH
I told you method should return true if original and reverse values are equal so where is this part in your code?
+ 2
PARUCHURI YASWANTH
Show your attempts.
+ 2
PARUCHURI YASWANTH
And don't make different thread for same question.
https://www.sololearn.com/Discuss/2667495/?ref=app
+ 2
PARUCHURI YASWANTH
Share your complete code.
+ 1
PARUCHURI YASWANTH
And check if original input and reverse input are equal then return true.
+ 1
Thank you so much sir
It works 😊
0
do { digit = num % 10; rev = (rev * 10) + digit; num = num / 10; } while (num != 0);
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;
}
0
Explanation in the comments:
https://code.sololearn.com/c1qOCghBDq6m/?ref=app
- 1
It's not working
- 1
#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;
}
- 1
Actual output is
8888 is a palindrome
- 1
Iam trying a lot
But it won't works sir