Advertisement
filipovv

checkNumIfPrime

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