Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MasterNumbers
- {
- class Program
- {
- static void Main(string[] args)
- {
- var input = int.Parse(Console.ReadLine());
- for (int i = 1; i < input; i++)
- {
- if (IsPalindrome(i) == true && IsDivisibleBySeven(i) == true && HoldEvenDigit(i) == true)
- {
- Console.WriteLine(i);
- }
- }
- }
- static bool IsPalindrome(int num)
- {
- int n = num;
- int rev = 0, dig;
- bool ispalindrome = false;
- while (n > 0)
- {
- dig = n % 10;
- rev = rev * 10 + dig;
- n = n / 10;
- }
- if (num == rev) ispalindrome = true;
- return ispalindrome;
- }
- static bool IsDivisibleBySeven(int num)
- {
- int sum = 0;
- foreach (var item in num.ToString())
- {
- sum += Convert.ToInt32(item.ToString());
- }
- if (sum % 7 == 0) return true;
- else return false;
- }
- static bool HoldEvenDigit(int num)
- {
- bool IsHoldEvenDig = false;
- foreach (var item in num.ToString())
- {
- if (Convert.ToInt32(item.ToString()) % 2 == 0) IsHoldEvenDig = true; ;
- }
- return IsHoldEvenDig;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment