+ 1

Another one with some bugs help me fixing it

https://code.sololearn.com/cStygyib3qx3/?ref=app

21st Nov 2020, 1:42 AM
NiTESH
NiTESH - avatar
2 Antworten
+ 2
Instead of trying to explain myself with a long post written in poor English, I just give you my solution. I know it's hard to understand programs written by someone else, but try to do it. https://code.sololearn.com/c0wtMk3i75gc/?ref=app
21st Nov 2020, 3:19 AM
Davide
Davide - avatar
+ 1
You are comparing sum to n. n is zero at the end of function as n is modified in each loops, so comparing sum with n gives false. You save the value of n in temporary variable and compare sum with it. The below code might help bool isPalindrome(int n){ int temp=n; while (n > 0){ int y = n%10; int sum = 0; sum += sum * 10 + y; n = n/10; if (sum == temp){ return true;} } return false; }
21st Nov 2020, 2:57 AM
rajshekhar y dodamani
rajshekhar y dodamani - avatar