Advertisement
Guest User

top number

a guest
Oct 21st, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 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.             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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement