Advertisement
martinvalchev

Master_Number

Feb 2nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Master_Number
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.             for (int i = 1; i <= n; i++)
  11.             {
  12.                 if (isPalindrom(i) && SumDigits7(i) && HasEvenDigits(i))
  13.                 {
  14.                     Console.WriteLine(i);
  15.                 }
  16.             }
  17.         }
  18.  
  19.          static bool HasEvenDigits(int i)
  20.         {
  21.             int current = 0;
  22.             bool hasEven = false;
  23.            while (i != 0)
  24.             {
  25.                 current = i % 10;
  26.                 if (current % 2 == 0)
  27.                 {
  28.                     hasEven = true;
  29.                     return hasEven;
  30.                 }
  31.                 i /= 10;
  32.             }
  33.             return hasEven;
  34.         }
  35.  
  36.          static bool SumDigits7(int i)
  37.         {
  38.             int sumDigit = 0;
  39.            while (i !=0)
  40.             {
  41.                 sumDigit += i % 10;
  42.                 i /= 10;
  43.             }
  44.            if (sumDigit % 7 == 0)
  45.             {
  46.                 return true;
  47.             }
  48.             else
  49.             {
  50.                 return false;
  51.             }
  52.         }
  53.  
  54.          static bool isPalindrom(int i)
  55.         {
  56.             int reverst = 0;
  57.             int oldNumber = i;
  58.             while (i != 0)
  59.             {
  60.                 reverst *= 10;
  61.                 reverst += i % 10;
  62.                 i /= 10;
  63.             }
  64.             if (reverst == oldNumber)
  65.             {
  66.                 return true;
  67.             } else
  68.             {
  69.                 return false;
  70.             }
  71.            
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement