daily pastebin goal
11%
SHARE
TWEET

top number

a guest Oct 21st, 2018 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.             for (int i = 1; i <= boundary; i++)
  16.             {
  17.                 int sumOfDigits = 0;
  18.                 bool hasOddDigit = false;
  19.                 int currentNumber = i;
  20.  
  21.                 while (currentNumber != 0)
  22.                 {
  23.                     int lastDigit = currentNumber % 10;
  24.                     sumOfDigits += lastDigit;
  25.  
  26.                     if (lastDigit % 2 == 1)
  27.                     {
  28.                         hasOddDigit = true;
  29.                     }
  30.  
  31.                     currentNumber /= 10;
  32.                 }
  33.  
  34.                 if (hasOddDigit && sumOfDigits % 8 == 0)
  35.                 {
  36.                     Console.WriteLine(i);
  37.                 }
  38.  
  39.             }
  40.         }
  41.     }
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top