mayap

PrimeNumberCheck

Apr 11th, 2014
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 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 PrimeNumbers
  8. {
  9.     class PrimeNumbers
  10.     {
  11.         static void Main()
  12.         {
  13.             int num;
  14.  
  15.             Console.WriteLine("Enter number: ");
  16.             num = int.Parse(Console.ReadLine());
  17.             if (num == 0 || num == 1)
  18.             {
  19.                 Console.WriteLine(num + " is not a prime number");
  20.                 Console.ReadLine();
  21.             }
  22.             else
  23.             {
  24.                 for (int a = 2; a <= Math.Sqrt(num); a++)
  25.                 {
  26.                     if (num % a == 0)
  27.                     {
  28.                         Console.WriteLine(num + " is not a prime number");
  29.                         return;
  30.                     }
  31.  
  32.                 }
  33.                 Console.WriteLine(num + " is a prime number");
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment