Advertisement
pavlinpetkov88

Check Prime

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