TheBulgarianWolf

Method example

Nov 1st, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3.  
  4. namespace ConsoleApp1
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Console.Write("Enter the final number: ");
  11.             int finalNum = int.Parse(Console.ReadLine());
  12.             TopNumber(finalNum);
  13.            
  14.  
  15.         }
  16.  
  17.         static void TopNumber(int finalNum)
  18.         {
  19.             for(int i = 1; i <= finalNum; i++)
  20.             {
  21.                 bool divisable = false;
  22.                 bool oddNum = false;
  23.                 int helpNum = 0;
  24.                 int helpNum2 = i;
  25.                 int sum = 0;
  26.                 while (helpNum2 > 0)
  27.                 {
  28.                     helpNum = helpNum2 % 10;
  29.                     if(helpNum % 2 != 0)
  30.                     {
  31.                         oddNum = true;
  32.                     }
  33.                     sum += helpNum;
  34.                     helpNum2 /= 10;
  35.                 }
  36.                 if(sum % 8 == 0)
  37.                 {
  38.                     divisable = true;
  39.                 }
  40.  
  41.                 if(divisable == true && oddNum == true)
  42.                 {
  43.                     Console.WriteLine(i);
  44.                 }
  45.             }
  46.         }
  47.        
  48.     }
  49. }
  50.  
Add Comment
Please, Sign In to add comment