Advertisement
dxeqtr

TopNumber

Jun 16th, 2020
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. using System;
  2. using System.Collections.Immutable;
  3. using System.Linq;
  4.  
  5. namespace _10.TopNumber
  6. {
  7. class Program
  8. {
  9. public static bool SumDigits(string input)
  10. {
  11. if (input.Sum(x => Convert.ToInt32(x)) % 8 == 0)
  12. return true;
  13.  
  14. else return false;
  15. }
  16.  
  17. public static bool ContainsOdd(int input)
  18. {
  19. if (input % 2 != 0)
  20. return true;
  21.  
  22. else return false;
  23.  
  24. }
  25. public static void TopNum(string input)
  26. {
  27. for (int i = 1; i <= int.Parse(input); i++)
  28. {
  29. if (SumDigits(i.ToString()) == true && ContainsOdd(i) == true)
  30. {
  31. Console.WriteLine(i);
  32. }
  33. }
  34. }
  35. static void Main(string[] args)
  36. {
  37. string input = Console.ReadLine();
  38.  
  39. TopNum(input);
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement