Advertisement
Guest User

Master Numbers

a guest
May 24th, 2016
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         int n = int.Parse(Console.ReadLine());
  8.         for (int i = 0; i <= n; i++)
  9.         {
  10.             if (IsPalindrome(i.ToString()) && SumDiv(i)) { Console.WriteLine(i); }
  11.         }
  12.     }
  13.  
  14.     static bool IsPalindrome(string n)
  15.     {
  16.         for (int i = 0; i < n.Length/2; i++)
  17.         {
  18.             if (n[i] != n[n.Length-1-i]) { return false; }
  19.         }
  20.         return true;
  21.     }
  22.     static bool SumDiv(int n)
  23.     {
  24.         bool evenDigit = false; bool divisible = false;
  25.         int sum = 0;
  26.         while (n != 0)
  27.         {
  28.             int lastDigit = n % 10;
  29.             if (lastDigit % 2 == 0) { evenDigit = true; }
  30.             sum += lastDigit;
  31.             n /= 10;
  32.         }
  33.         if (sum%7==0) { divisible = true; }
  34.         if (evenDigit&&divisible) { return true; }
  35.         else { return false; }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement