Advertisement
VelizarAvramov

05. Special Numbers

Nov 14th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _05._Special_Numbers
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.  
  11.             // 356
  12.             //356 % 10 ->  6!
  13.             //356 / 10 -> 35
  14.             //35 % 10  ->  5!
  15.             //35 / 10  -> 3
  16.             //3 % 10   ->  3!
  17.             //3 / 10   -> 0
  18.  
  19.             for (int i = 1; i <= n; i++)
  20.             {
  21.                 int number = i;
  22.                 int sum = 0;
  23.                 while (number != 0)
  24.                 {
  25.                     int currentNumber = number % 10;
  26.                     number /= 10;
  27.                     sum += currentNumber;
  28.                 }
  29.                 bool isSpecial = false;
  30.  
  31.                 if (sum == 5 || sum == 7 || sum == 11)
  32.                 {
  33.                     isSpecial = true;
  34.                 }
  35.                 Console.WriteLine($"{i} -> {isSpecial}");
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement