saimun1

Prime or Not

Jul 19th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.66 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 Test
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             int n = int.Parse(Console.ReadLine());
  15.             var prime = true;
  16.             for (int i = 2; i <= Math.Sqrt(n); i++)
  17.             {
  18.                 if(n % i == 0)
  19.                 {
  20.                     prime = false;
  21.                     break;
  22.                 }
  23.             }
  24.             if (prime)
  25.                 Console.WriteLine("Prime");
  26.             else
  27.                 Console.WriteLine("Not prime");
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment