Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _10._TopNumber
- {
- class TopNumber
- {
- static void Main()
- {
- int num = int.Parse(Console.ReadLine());
- for (int i = 0; i <= num; i++)
- {
- bool isTopNum = isTopNumber(i);
- if (isTopNumber(i))
- {
- Console.WriteLine(i);
- }
- }
- }
- static bool isTopNumber(int num)
- {
- bool isDivisible = false;
- bool isOddDigit = false;
- int temp = num;
- int sum = 0;
- while (temp > 0)
- {
- int digit = temp % 10;
- sum += digit;
- temp /= 10;
- if (digit % 2 != 0)
- {
- isOddDigit = true;
- }
- }
- if (sum % 8 == 0)
- {
- isDivisible = true;
- }
- return isDivisible && isOddDigit;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement