Advertisement
koksibg

Master_Numbers

Oct 7th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 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 Master_Numbers
  8. {
  9.     class Master_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.             if (IsPalindrome(num) && SumOfDigits(num) && ContainEvenDigit(num))
  16.             Console.WriteLine(num);
  17.         }
  18.  
  19.          static bool IsPalindrome(int num)
  20.         {
  21.             int n = num;
  22.             int reverse = 0;
  23.             while (num > 0)
  24.             {
  25.                 int digit = num % 10;
  26.                 reverse = reverse * 10 + digit;
  27.                 num = num / 10;
  28.             }
  29.             if (n == reverse) return true;
  30.             else return false;
  31.         }
  32.  
  33.         static bool SumOfDigits(int num)
  34.         {
  35.             int sum = 0;
  36.             while (num > 0)
  37.             {
  38.                 sum += num % 10;
  39.                 num = num / 10;
  40.             }
  41.             if (sum % 7 == 0) return true;
  42.             else return false;
  43.         }
  44.  
  45.         static bool ContainEvenDigit(int num)
  46.         {
  47.             while (num > 0)
  48.             {
  49.                 if (num % 10 % 2 == 0) return true;
  50.                 num /= 10;
  51.             }
  52.             return false;
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement