nikolayneykov

Untitled

Feb 22nd, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _10TopNumber
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int totalNumbers = int.Parse(Console.ReadLine());
  10.  
  11.             for (int number = 1; number <= totalNumbers; number++)
  12.             {
  13.                 if (SumOfDigits(number) && OddDigits(number))
  14.                 {
  15.                     Console.WriteLine(number);
  16.                 }
  17.             }
  18.         }
  19.  
  20.         static bool SumOfDigits(int input)
  21.         {
  22.             int sum = 0;
  23.  
  24.             while (input > 0)
  25.             {
  26.                 sum += input % 10;
  27.                 input /= 10;
  28.             }
  29.  
  30.             return sum % 8 == 0;
  31.         }
  32.  
  33.         static bool OddDigits(int input)
  34.         {
  35.             while (input > 0)
  36.             {
  37.                 if ((input % 10) % 2 == 1)
  38.                 {
  39.                     return true;
  40.                 }
  41.                 input /= 10;
  42.             }
  43.             return false;
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment