Advertisement
SergeyPGUTI

6.1.8

Oct 24th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. bool IsPalindrome (int n)
  6. {
  7.     int n1=n,NewN=0;
  8.     int k=0;
  9.     while (n1>0)
  10.     {
  11.  
  12.         k=n1%10;
  13.         NewN+=k;
  14.         n1/=10;
  15.         NewN*=10;
  16.     }
  17.     NewN/=10;
  18.     return (NewN==n)? true:false;
  19. }
  20.  
  21. int main()
  22. {
  23.     int n;
  24.     cin>>n;
  25.     int sum=0;
  26.     for (int i=1;i<=n;i++)
  27.         if (IsPalindrome(i)) sum++;
  28.     cout<<sum;
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement