Advertisement
fbinnzhivko

Prime Checker

May 19th, 2016
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.61 KB | None | 0 0
  1. using System;
  2. class Program
  3. {
  4.     static void Main()
  5.     {
  6.         double n = double.Parse(Console.ReadLine()); ;
  7.         int counter = (int)Math.Sqrt(n);
  8.         bool isPrime = true;
  9.         if (n > 1)
  10.         {
  11.             for (int cnt = 2; cnt <= counter; cnt++)
  12.             {
  13.                 if (n % cnt == 0)
  14.                 {
  15.                     isPrime = false;
  16.                     break;
  17.                 }
  18.             }
  19.         }
  20.         else
  21.         {
  22.             isPrime = false;
  23.         }
  24.         if (isPrime) { Console.WriteLine(true); }
  25.         else { Console.WriteLine(false); }
  26.  
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement