+ 6
C++ Palindrome Numbers help
Can't solve this after many trials If i put this 👇🏻 only test case 2,5,6 and then 1,3,4 case is coming wrong trying from 3-4 days 🙏🏻help #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; }
9 ответов
+ 7
#include <iostream>
using namespace std;
bool isPalindrome(int x) {
//complete the function
int y=x,z=0;
while(x!=0)
{
z=z*10+x%10;
x=x/10;
}
if(y==z)
return(true);
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;
}
It work run it
+ 2
You didn't have to write x=n because n is not the same as in main function
In function you remove n and replace it by x
And also you have to return true and false in bool function
+ 2
Change 'x=n' to 'n=x'
After while loop add:
if(s==n)
return 1;
else
return 0;
+ 2
Remove n from bool function only take x and return true and false
+ 1
Not working I have tried you answer
+ 1
#include <iostream>
using namespace std;
bool isPalindrome(int x) {
//complete the function
int temp, rev=0, digit;
temp = x;
do
{
digit = temp % 10;
rev = (rev*10) + digit;
temp = temp / 10;
} while (temp !=0);
if (x == 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;
}
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;
}