dakata

MasterNumbers

Jan 29th, 2017
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 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 MasterNumbers
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var input = int.Parse(Console.ReadLine());
  14.  
  15.             for (int i = 1; i < input; i++)
  16.             {
  17.                 if (IsPalindrome(i) == true && IsDivisibleBySeven(i) == true && HoldEvenDigit(i) == true)
  18.                 {
  19.                     Console.WriteLine(i);
  20.                 }
  21.             }
  22.  
  23.         }
  24.  
  25.         static bool IsPalindrome(int num)
  26.         {
  27.             int n = num;
  28.             int rev = 0, dig;
  29.             bool ispalindrome = false;
  30.  
  31.             while (n > 0)
  32.             {
  33.                 dig = n % 10;
  34.                 rev = rev * 10 + dig;
  35.                 n = n / 10;
  36.             }
  37.             if (num == rev) ispalindrome = true;
  38.  
  39.             return ispalindrome;
  40.         }
  41.  
  42.         static bool IsDivisibleBySeven(int num)
  43.         {
  44.             int sum = 0;
  45.             foreach (var item in num.ToString())
  46.             {
  47.                 sum += Convert.ToInt32(item.ToString());
  48.             }
  49.             if (sum % 7 == 0) return true;
  50.             else return false;
  51.         }
  52.  
  53.         static bool HoldEvenDigit(int num)
  54.         {
  55.             bool IsHoldEvenDig = false;
  56.             foreach (var item in num.ToString())
  57.             {
  58.                 if (Convert.ToInt32(item.ToString()) % 2 == 0) IsHoldEvenDig = true; ;
  59.             }
  60.            
  61.             return IsHoldEvenDig;
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment