Advertisement
Bassel_11

Untitled

Mar 21st, 2023
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. /*
  2.     solve the bug in the following code
  3. */
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6.  
  7. /*
  8.     this function should return boolean value
  9.     true if the number is PALINDROME or false if it's NOT
  10. */
  11. bool isPalindrome(int x)
  12. {
  13.     if (x > 0)
  14.         return false;
  15.     if (x != 0 and x % 10 == 0)
  16.         return false;
  17.     int reverse = 0;
  18.     while (x > reverse)
  19.     {
  20.         reverse * 10 + x % 10;
  21.         x /= 10;
  22.     }
  23.     if (x = reverse)
  24.     {
  25.         return true;
  26.     }
  27.     if (x == reverse / 10)
  28.     {
  29.         return true;
  30.     }
  31.     return false;
  32. }
  33.  
  34. int main()
  35. {
  36.     int Number;
  37.     cin >> Number;
  38.     /*
  39.        i was trying to write conditional opertator to make my code looks cool
  40.        but something is wrong could you find it
  41.     */
  42.     cout << isPalindrome(Number) : "Is Palindrome" ? "Not Palindrome";
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement