Advertisement
Guest User

top number

a guest
Oct 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _10.Top_Number
  4. {
  5.     class TopNumber
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int endNumber = int.Parse(Console.ReadLine());
  10.             FindingTopNumbers(endNumber);
  11.         }
  12.  
  13.         private static void FindingTopNumbers(int boundary)
  14.         {
  15.            
  16.  
  17.             for (int i = 1; i <= boundary; i++)
  18.             {
  19.                 int sumOfDigits = 0;
  20.                 bool hasOddDigit = false;
  21.                 int currentNumber = i;
  22.  
  23.                 while (currentNumber != 0)
  24.                 {
  25.                     int lastDigit = currentNumber % 10;
  26.                     sumOfDigits += lastDigit;
  27.  
  28.                     if (lastDigit % 2 == 1)
  29.                     {
  30.                         hasOddDigit = true;
  31.                     }
  32.  
  33.                     currentNumber /= 10;
  34.                 }
  35.  
  36.                 if (hasOddDigit && sumOfDigits % 8 == 0)
  37.                 {
  38.                     Console.WriteLine(i);
  39.                 }
  40.  
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement