2008-08-30, 04:12 AM
Code:
if (i == num)
{
Console.WriteLine(num);
}That makes me cry. Writelines are very CPU intensive. Only the end result is needed.

Code:
Stopwatch timer = new Stopwatch();
timer.Start();
int num;
int i;
for (num = 3; num <= cap; num += 2)
{
for (i = 2; i < num; i++)
{
if (num % i == 0)
{
break;
}
}
}There are other optimizations you could use, but these are some pretty good ones for the moment. I guess it's also because I was trained in the ANSI standard. >_>
