Advertisement
braveheart1989

Special_Numbers

Mar 16th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _06.Special_Numbers
  8. {
  9.     class Special_Numbers
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             for (int num = 1; num <= n; num++)
  15.             {
  16.                 int sumOfdigit = 0;
  17.                 int digit = num;
  18.                 while (digit > 0)
  19.                 {
  20.                     sumOfdigit += digit % 10;
  21.                     digit /= 10;
  22.                 }
  23.  
  24.                 bool isSpecial = (sumOfdigit == 5 && (sumOfdigit % 5 == 0)) ||
  25.                     (sumOfdigit == 7 && (sumOfdigit % 7 == 0)) || (sumOfdigit == 11 && (sumOfdigit % 11 == 0));
  26.                 Console.WriteLine("{0} -> {1}", num, isSpecial);
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement