csansoon

P4.13 P77686 Palindromic numbers

Oct 24th, 2018
774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool is_palindromic(int n) {
  5.    int x = n, r = 0, z;
  6.    bool v;
  7.    for (int i = 1; x != 0; i++) {
  8.         z = x%10;
  9.         x = x/10;
  10.         r = z+(r*10);
  11.    }
  12.    if (r == n) v = true;
  13.    else v = false;
  14.    return v;
  15. }
  16.    
  17. int main(){
  18.     int n;
  19.     cin >> n;
  20.     cout<<is_palindromic(n)<<endl;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment