/ Published in: C#
Method to Check if an int is a Prime Number
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
static bool isPrime(int number) { if (number == 1) return true; if (number == 2) return true; if (number == 3) return true; if (number == 4) return false; for (int i = 2; i <= Math.Ceiling(Math.Sqrt(Convert.ToDouble(number))); i++) { if (number % i == 0) { return false; } } return true; }