+ 1

Hi coders can you help me solve this because I tried but failed

A palindromic number is a number (such as 626) that remains the same when its digits are reversed. 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. #include <iostream> using namespace std; bool isPalindrome(int arr[],int x) { //complete the function for(x=0;x<=3;x++) cout <<arr[x]; } int main() { int n; cin >>n; if(isPalindrome(n)==arr[x]) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }

15th May 2022, 2:47 AM
Soneta
Soneta - avatar
3 odpowiedzi
+ 3
Hello Soneta, Many people had asked questions around this task, so it is recommended of us to search for similar discussion threads to learn from. Code section may also help if you need examples 👍
15th May 2022, 3:22 AM
Ipang
+ 2
19th May 2022, 2:39 AM
Soneta
Soneta - avatar
+ 1
Before that i think you need to revise the topic before you attempting.. Your function definition has 2 parameter but your calling function has only 1 argument.. So it's undefined function then. And in main arr[x] where arr, x are both undefined.. In function, you are just printing arr values. Not returning any boolean value.. Instead you need to find reversing of number and compare with original number, if equals return true else return false. Implement it in isPolindrome(int n) function And in main, if block just call like if ( isPolindrome(n) ) { .. } ( you can also return reversed number to main and then compare in main like if ( isPolindrome(n) == n) { .. } Hope it helps...
15th May 2022, 10:32 AM
Jayakrishna 🇮🇳