NastySwipy

MethodsDebugging&Troubleshootig Code - 06. Prime Checker

May 31st, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4.  
  5. namespace _04b_MethodsDebuggingTroubleshootingCode_Exercises
  6. {
  7.     class MethodsDebuggingTroubleshootingCode_Exercises
  8.     {
  9.       static void Main(string[] args)
  10.         {
  11.             long num = long.Parse(Console.ReadLine());
  12.             Console.WriteLine(ReturnisPrime(num));
  13.         }
  14.        
  15.         static bool ReturnisPrime(long num)
  16.         {
  17.             num = Math.Abs(num);
  18.             if (num == 0) return false;
  19.             if (num == 1) return false;
  20.             if (num == 2) return true;
  21.  
  22.             for (long i = 2; i <= Math.Ceiling(Math.Sqrt(num)); ++i)
  23.             {
  24.                 if (num % i == 0) return false;
  25.             }
  26.             return true;
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment