1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | public static void IsPrime(int n) { foreach (var num in Enumerable.Range(2, n-1)) { if (num == 2) { Console.WriteLine(num); continue; } var result = true; for (int i = 2; i <= (int)Math.Sqrt(num); i++) { if (num % i == 0) { result = false; break; } } if (result) Console.WriteLine(num); } } |