Finding Prime Numbers

Here’s my prime number algorithm implementation that I have written in C#.

public static bool IsPrime(int x)
{
if (x <= 1)
return false;
else
{
double i = 2;

bool r = true;
while (i <= Math.Sqrt(x))
{
if ((x / i) % 1 == 0)
{
r = false;
break;
}
i++;
}
return r;
}
}

0 Responses to “Finding Prime Numbers”



  1. No Comments Yet

Leave a Reply





Robert Sundström

Tweets

  • Waiting for the VS 2010 Beta 2 to be released to public. Only a couple of hours left. But still not sure when. Is it local time? 1 month ago
  • Writing meaningless programs.. 1 month ago
  • I consider myself being a logical being, but my logic is flaud. 1 month ago
  • SvD: Facebook gör dig smart – men Twitter fördummar (http://bit.ly/14XGNr 2 months ago
  • 2 weeks have passed since I came to Karlskrona. I pretty much enjoy living here. College has started and so far little coursework. 2 months ago

Recent Comments

Steve on Windows 3.11 on a virtual…
catchmikey on Wakoopa
Hillary on First days in Delsbo
wilhol on PC or Mac?

Categories

Calendar

February 2008
M T W T F S S
    May »
 123
45678910
11121314151617
18192021222324
2526272829  

Blog Stats

  • 15,582 hits