Advertisement
kirililchev3

Special Numbers - bool

May 24th, 2018
140
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 P05SpecialNumbers
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.  
  11.             for (int num = 1; num <= n; num++)
  12.             {
  13.                 int sumOfDigits = 0;
  14.                 int digits = num;
  15.                 while (digits > 0)
  16.                 {
  17.                     sumOfDigits += digits % 10;
  18.                     digits = digits / 10;
  19.                 }
  20.                 bool special = (sumOfDigits == 5 || sumOfDigits == 7 || sumOfDigits == 11);
  21.                 Console.WriteLine("{0} -> {1}", num, special);
  22.             }
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement