Advertisement
Spocoman

12. Refactor Special Numbers

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