Hey,
I was bored today, so i made a little program that calculates primes..
it works, but my question is how can i make it more efficient?
Here is the source:
Thanks in advance!
I was bored today, so i made a little program that calculates primes..
it works, but my question is how can i make it more efficient?
Here is the source:
Code
class Program
{
private static int num = 1;
private static bool unlimited = false;
static void Main()
{
while(true)
{
if (IsPrime(num))
{
Console.WriteLine(num);
if (!unlimited)
{
Console.ReadKey();
Console.Clear();
}
}
num += 1;
}
}
public static bool IsPrime(int number)
{
double boundary = Math.Floor(Math.Sqrt(number));
if (number == 1) return false;
if (number == 2) return true;
for (int i = 2; i <= boundary; ++i)
{
if (number % i == 0) return false;
}
return true;
}
}Thanks in advance!


