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