Advertisement
llvlleo1810

Tìm số đẹp (thuận nghịch và chia hết cho 10)

Apr 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int n;
  6.  
  7. bool ThuanNghich(int x) {
  8.  int tmp = x;
  9.  int dao = 0;
  10.  while(x > 0) {
  11.   dao = dao*10 + x%10;
  12.   x /= 10;
  13.  }
  14.  if(dao == tmp)
  15.   return true;
  16.  return false;
  17. }
  18.  
  19. bool tongchia10(int n) {
  20.  int tong = 0;
  21.  while(n > 0) {
  22.   int t = n % 10;
  23.   tong = tong + t;
  24.   n = n / 10;
  25.  }
  26.  if(tong%10==0)
  27.   return true;
  28.  return false;
  29. }
  30.  
  31. int main() {
  32.  cin >> n;
  33.  int dem = 0;
  34.  for(int i = pow(10,n-1); i < pow(10,n); i++)
  35.   if(ThuanNghich(i) && tongchia10(i))
  36.    dem++;
  37.  cout << dem;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement