Advertisement
dinko_dt

Untitled

Feb 8th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5.  
  6. namespace _10._Top_Number
  7. {
  8. class Top_Number
  9. {
  10. static void Main()
  11. {
  12. int topNumber = int.Parse(Console.ReadLine());
  13.  
  14. for (int i = 1; i < topNumber; i++)
  15. {
  16. bool isTopNum = IsTopNumber(i);
  17. if (isTopNum)
  18. {
  19. Console.WriteLine(i);
  20. }
  21. }
  22.  
  23. }
  24.  
  25. static bool IsTopNumber(int number)
  26. {
  27. bool isDivisible = false;
  28. bool isOddDigit = false;
  29. int sum = 0;
  30.  
  31. while (number != 0)
  32. {
  33.  
  34. int digit = number % 10;
  35. number /= 10;
  36. sum += digit;
  37. if (digit % 2 == 1)
  38. {
  39. isOddDigit = true;
  40. }
  41. }
  42. if (sum % 8 == 0)
  43. {
  44. isDivisible = true;
  45. }
  46. return isDivisible && isOddDigit;
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement