Advertisement
VladoG

[Programming Fundamentals] - 23. Prime Checker

Jun 1st, 2016
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 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 _23_Prime_Checker
  8.     {
  9.     class PrimeChecker
  10.         {
  11.         static void Main(string[] args)
  12.             {
  13.             long num = long.Parse(Console.ReadLine());
  14.  
  15.             Console.WriteLine(IsPrime(num));
  16.  
  17.             } // End of Main
  18.  
  19.         public static bool IsPrime(long n)
  20.             {
  21.             bool checkPrime;
  22.  
  23.             if (n<2)
  24.                 {
  25.                 checkPrime = false;
  26.                 }
  27.             else
  28.                 {
  29.                 checkPrime = true;
  30.                 for (long i = 2; i < n; i++)
  31.                     {
  32.                     if (n%i==0)
  33.                         {
  34.                         checkPrime = false;
  35.                         break;
  36.                         }
  37.                     }
  38.                 }
  39.  
  40.             return checkPrime;
  41.             }
  42.  
  43.         }
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement