petarkobakov

Top Number

Jun 19th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Top_Number
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int n = int.Parse(Console.ReadLine());
  10. PrintTopNum(n);
  11. }
  12. static void PrintTopNum(int n)
  13. {
  14. for (int i = 1; i <=n; i++)
  15. {
  16. int current = i;
  17. int digitsSum = 0;
  18. bool isDivided = false;
  19. bool hasOddDigit = false;
  20.  
  21. while (current > 0)
  22. {
  23.  
  24. int digit = current % 10;
  25. digitsSum += digit;
  26.  
  27. if (digit%2 == 1)
  28. {
  29. hasOddDigit = true;
  30. }
  31.  
  32. current /= 10;
  33.  
  34. }
  35. if (digitsSum % 8 == 0)
  36. {
  37.  
  38. isDivided=true;
  39. }
  40. if (isDivided == true && hasOddDigit == true)
  41. {
  42. Console.WriteLine(i);
  43. }
  44. }
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment