Advertisement
fbinnzhivko

Master Numbers

May 19th, 2016
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 KB | None | 0 0
  1. using System;
  2. namespace specialNumbers
  3. {
  4.     class Program
  5.     {
  6.         static bool isPalindrome(int num)
  7.         {
  8.             string sNum = num.ToString();
  9.             for (int i = 0; i < sNum.Length; i++)
  10.                 if (sNum[i] != sNum[sNum.Length - 1 - i]) return false;
  11.  
  12.             return true;
  13.         }
  14.         static bool SumOfDigits(int n)
  15.         {
  16.             int sum = 0;
  17.             while (n > 0)
  18.             {
  19.                 sum += n % 10;
  20.                 n = n / 10;
  21.             }
  22.             if (sum % 7 == 0)
  23.             {
  24.                 return true;
  25.             }
  26.             else
  27.             {
  28.                 return false;
  29.             }
  30.  
  31.  
  32.         }
  33.         static bool ContainsEvenDigit(int num)
  34.         {
  35.            string n = num.ToString();
  36.             for (int i = 0; i < n.Length; i++)
  37.             {
  38.                 if (n[i] % 2 == 0)
  39.                 {
  40.                     return true;
  41.                 }
  42.  
  43.             }
  44.             return false;
  45.  
  46.         }
  47.  
  48.         static void Main()
  49.         {
  50.             int n = int.Parse(Console.ReadLine());
  51.             for (int i = 1; i <= n; i++)
  52.             {
  53.                 if (isPalindrome(i) && SumOfDigits(i) && ContainsEvenDigit(i))
  54.                 {
  55.                     Console.WriteLine(i);
  56.                 }
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement