Advertisement
ralka

Untitled

Jun 30th, 2016
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 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 _33.Prime_Checker
  8. {
  9.     class PrimeChecker
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             long num = long.Parse(Console.ReadLine());
  14.  
  15.             bool isPrime = IsPrime(num);
  16.             Console.WriteLine(isPrime);
  17.         }
  18.  
  19.         private static bool IsPrime(long num)
  20.         {
  21.             int div = 2;
  22.             bool isPrime = true;
  23.  
  24.             if (num <= 1)
  25.             {
  26.                 isPrime = false;
  27.             }
  28.             else
  29.             {
  30.                 while (div <= Math.Sqrt(num))
  31.                 {
  32.                     if (num % div == 0)
  33.                     {
  34.                         isPrime = false;
  35.                     }
  36.                     div++;
  37.                 }
  38.             }
  39.            
  40.  
  41.             return isPrime;
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement