Guest User

Untitled

a guest
Feb 19th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. unsigned func (unsigned x1, unsigned x2, unsigned k)
  4. {
  5. if (k == 1)
  6. return 0;
  7. x1 /= 10;
  8. x2 = x1 % 10;
  9. return x2 * k / 10 + func (x1, x2, k / 10);
  10. }
  11.  
  12. unsigned count (unsigned x)
  13. {
  14. if (x < 10)
  15. return 1;
  16. return (count (x / 10) + 1);
  17. }
  18.  
  19. unsigned rev (unsigned x)
  20. {
  21. unsigned res, k, i, j, power, y, N;
  22. k = count (x);
  23. power = 1;
  24. for (j = 1; j < k; j++)
  25. power *= 10;
  26. if (power == 1)
  27. res = x;
  28. else
  29. {
  30. y = x % 10;
  31. res = func (x*10, y, power*10);
  32. }
  33. return res;
  34. }
  35.  
  36. int main(void)
  37. {
  38. unsigned x, res, k, i, j, power, y, N;
  39. scanf("%u %u", &x, &N);
  40. for (i = 0; i < N ; i++)
  41. {
  42. x += rev (x);
  43. }
  44.  
  45. if (x == rev (x))
  46. printf("Yes\n%u\n", x);
  47. else
  48. printf("No\n");
  49. return 0;
  50. }
Add Comment
Please, Sign In to add comment