Advertisement
bullit3189

Top Number

Jan 23rd, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5.  
  6. public class Program
  7. {
  8. public static void Main()
  9. {
  10. int num = int.Parse(Console.ReadLine());
  11. TopNumber (num);
  12. }
  13. public static void TopNumber (int n)
  14. {
  15. for (int i=1; i<=n; i++)
  16. {
  17. int currNum =i;
  18. int currNumCopy = i;
  19. int counter =0;
  20. int sum =0;
  21.  
  22. while (currNumCopy !=0)
  23. {
  24. int lastDigit = currNumCopy%10;
  25. if (lastDigit %2!=0)
  26. {
  27. counter++;
  28. }
  29. currNumCopy /=10;
  30. sum+=lastDigit;
  31. }
  32. if (sum%8==0 && counter>0)
  33. {
  34. Console.WriteLine(currNum);
  35. }
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement