- 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

2nd Jan 2021, 4:40 AM
Coder Ayush
Coder Ayush - avatar
8 Antworten
- 1
You have to code this function for this to work. bool isPalindrome(int x) { //complete the function }
2nd Jan 2021, 4:46 AM
noteve
noteve - avatar
+ 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 :)
21st Jan 2021, 7:52 AM
seMza
seMza - avatar
+ 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; }
1st Jul 2021, 7:45 AM
Shreyas S
+ 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; }
29th Sep 2022, 10:53 AM
Darshit Vaghasiya
Darshit Vaghasiya - avatar
0
You need to complete the bool function first "//complete the function".
2nd Jan 2021, 4:50 AM
Mohamed Kharma
Mohamed Kharma - avatar
0
15th Apr 2021, 6:29 AM
Luis Miguel Espitia Santana
Luis Miguel Espitia Santana - avatar
- 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; }
25th Oct 2021, 10:09 PM
Hoang Minh
Hoang Minh - avatar
- 3
idk semza code is working perfectly why people didn't like
15th Apr 2021, 10:47 PM
ÖZKAN TÜRİDİ
ÖZKAN TÜRİDİ - avatar