Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C# beginner

Name: Frost 2007-01-16 2:28

OK, first semester in C# and just starting to work on it.  Haven't programmed in a long time, kinda stumped on this one.  The assignment is to determine if a number is prime, and if its not, to factor it.  I know what a prime number is in my head, but I don't really know how to put that into code.

Thanks.

Name: Anonymous 2007-01-17 17:50 (sage)

>>12-14
this is probably efficient enough for most purposes...
may require some changes to work in your shitty language...

#include <math.h>
int is_prime(int n){for(int i=2;i<=sqrt(n);++i)n=n%i?n:0;return n>1;}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List