Advertisement
Guest User

Untitled

a guest
May 24th, 2016
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. using System;
  2. namespace MasterNumbers
  3. {
  4. class MasterNumbers
  5. {
  6. static void Main()
  7. {
  8. int n = int.Parse(Console.ReadLine());
  9. for (int i = 1; i <= n; i++)
  10. {
  11. if (isPalindrome(i) && SumOfDigits(i) && ContainsEvenDigit(i))
  12. {
  13. Console.WriteLine(i);
  14. }
  15. }
  16. }
  17. static bool isPalindrome(int num)
  18. {
  19. string sNum = num.ToString();
  20. for (int i = 0; i < sNum.Length; i++)
  21. if (sNum[i] != sNum[sNum.Length - 1 - i]) return false;
  22. return true;
  23. }
  24. static bool SumOfDigits(int n)
  25. {
  26. int sum = 0;
  27. while (n > 0)
  28. {
  29. sum += n % 10;
  30. n = n / 10;
  31. }
  32. if (sum % 7 == 0)
  33. {
  34. return true;
  35. }
  36. else
  37. {
  38. return false;
  39. }
  40. }
  41. static bool ContainsEvenDigit(int num)
  42. {
  43. string n = num.ToString();
  44. for (int i = 0; i < n.Length; i++)
  45. {
  46. if (n[i] % 2 == 0)
  47. {
  48. return true;
  49. }
  50. }
  51. return false;
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement