+ 2

palindrome number problem

Hi everyone recently I've been learning about programming and I'm having some difficulties with this task: "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 To check if a number is palindrome, you need to reverse it and compare with the original one." So far I've got this: but the program won't accept it, and I feel stuck. Can someone gime me some advice/ideas #include<iostream> using namespace std; int main() { int n,num,digit, rev=0; cout<<"Enter the number to check if it is a palindome or not: "<<endl; cin>>num; n=num; do { digit = num%10; rev=(rev*10)+digit; num=num/10; } while (num=!0) cout<<"the reverse number is: "<<rev<<endl; if(n==rev) cout<<"the number is a Palindome"<<endl; else cout<<"the number is not a Palindrome"; return 0; }

8th Jan 2021, 2:30 PM
Laura Daniela Di Ninno
Laura Daniela Di Ninno - avatar
4 Réponses
+ 8
There are several problems in your program Compilation errors and warnings 1) semicolon missing after do-while loop 2) ( num =!0 ) inequality use incorrectly. Question specific problems. the output should be STRICTLY according to what is given in the question statement. your program displays much more extra stuff than asked ideally, you should not have even touched the main() function of the provided program and should have completed the isPalindrom() function instead
8th Jan 2021, 2:43 PM
Arsenic
Arsenic - avatar
0
Hello
9th Jan 2021, 7:23 PM
Чоми Абдурахмон
Чоми Абдурахмон - avatar
0
Great!
10th Jan 2021, 10:45 AM
Zannatul Naim
Zannatul Naim - avatar