Advertisement
Razhagal

Prime Checker

Mar 31st, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 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. class PrimeCheckerMethod
  8. {
  9.     static bool PrimeChecker(long input)
  10.     {
  11.         if (input < 2)
  12.         {
  13.             return false;
  14.         }
  15.         else
  16.         {
  17.             int divider = 2;
  18.             double maxDivider = Math.Sqrt(input);
  19.  
  20.             while (divider <= maxDivider)
  21.             {
  22.                 if (input % divider == 0)
  23.                 {
  24.                     return false;
  25.                 }
  26.  
  27.                 divider++;
  28.             }
  29.         }
  30.  
  31.         return true;
  32.     }
  33.  
  34.     static void Main()
  35.     {
  36.         long number = long.Parse(Console.ReadLine());
  37.  
  38.         Console.WriteLine("\"{0}\" is prime? {1}", number, PrimeChecker(number));
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement