VelizarAvramov

09. Refactor Special Numbers

Nov 15th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.66 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Demo
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.            
  11.             for (int i = 1; i <= n; i++)
  12.             {
  13.                 int sum = 0;
  14.                 int current = i;
  15.                 while (current > 0)
  16.                 {
  17.                     sum += current % 10;
  18.                     current /= 10;
  19.                 }
  20.                 bool isSpecial = false;
  21.                 isSpecial = (sum == 5) || (sum == 7) || (sum == 11);
  22.                 Console.WriteLine($"{i} -> {isSpecial}");              
  23.             }
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment