- 2
A palindromic number is a number (such as 626) that remains the same when its digits are reversed. Write a function that returns
#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; } What I have written wrong in this code i am trying this from 10 minutes but it gives me null please type the code in answer
8 Respuestas
- 1
You have to code this function for this to work.
bool isPalindrome(int x) {
//complete the function
}
+ 9
#include <iostream>
using namespace std;
int main()
{
int n, num, digit, rev = 0;
cin >> num;
n = num;
do
{
digit = num % 10;
rev = (rev * 10) + digit;
num = num / 10;
} while (num != 0);
if (n == rev)
cout <<n<<" is a palindrome";
else
cout <<n<<" is NOT a palindrome";
return 0;
}
I think it will help you :)
+ 4
#include <iostream>
using namespace std;
int revdigit(int y){
int rem, rev=0;
while(y>0){
rem = y%10;
rev = rev*10+rem;
y = y/10;
}return rev;
}
bool isPalindrome(int x) {
//complete the function
if(x==revdigit(x)){
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;
}
+ 1
#include <iostream>
using namespace std;
int main()
{
int n, num, digit, rev = 0;
cin >> num;
n = num;
do
{
digit = num % 10;
rev = (rev * 10) + digit;
num = num / 10;
} while (num != 0);
if (n == rev)
cout <<n<<" is a palindrome";
else
cout <<n<<" is NOT a palindrome";
return 0;
}
0
You need to complete the bool function first "//complete the function".
0
- 1
#include <iostream>
using namespace std;
bool isPalindrome(int x) {
//complete the function
int temp = x;
int lastDigit, reverse = 0;
while (x>0)
{
lastDigit = x % 10;
reverse = (reverse*10) + lastDigit;
x/=10;
}
if (temp == reverse)
{
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;
}
- 3
idk semza code is working perfectly why people didn't like