Advertisement
llvlleo1810

Tìm số đẹp(số thuận nghịch lộc phát)

Aug 7th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int cstn (int n)
  4. {
  5.     int k = n, sdn = 0;
  6.     while (k) {
  7.         sdn = sdn * 10 + k % 10;
  8.         k /= 10;
  9.     }
  10.     return sdn == n;
  11. }
  12.  
  13. int cslp(int n)
  14. {
  15.     int sum = 0, kt = 0;
  16.     while (n) {
  17.         sum += n % 10;
  18.         kt = n % 10 == 6 ? 1 : kt;
  19.         n /= 10;
  20.     }
  21.     return kt && sum % 10 == 8;
  22. }
  23.  
  24. int main()
  25. {
  26.     int a, b;
  27.     scanf("%d %d", &a, &b);
  28.     for (int i = (a < b ? a : b); i <= (a < b ? b : a); i++) {
  29.         cstn(i) && cslp(i) ? printf("%d ", i) : 0;
  30.     }
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement