Advertisement
MZlatev

Untitled

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