http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> Just 4 fun I want to write a program to tell if numberz are prime.

> I will enter a number, and for all numbers 1 to that number it will say "N is prime" or "N is not prime".

> And it should be recursuve. What duz that mean?

> Can u show me how to do it?
/* Sure! I am always happy to help.

This program implements a blindingly fast O(n^n) algorithm

to find prime numbers, using an elegant recursive method. */

int _(int n, int m, int d, int p)

{

int i, r = m != n;

switch(p)

{

case 0:

for(i=0; d && (i<n); i=_(i,1,d,1))

r = _(r,_(n,(m<=n)?_(i,m,d,2):0,d-1,0)|!_(i,1,i,0),

0,2);

break;

case 1:

r = n ? 1 + _(n-1,m,d,1) : m ? 1 + _(n,m-1,d,1) : 0;

break;

case 2:

r = m ? _(n,_(n,m-1,d,2),0,1) : m;

}

return r;

}

/*------------------------------------------

Print primes up to the requested value

--------------------------------------------*/

int main(int argc, char* argv[])

{

int n, max;

scanf("%d",&max);

for(n = 2; n <= max; n++)

printf("%d is%s prime\n",n, _(n,1,n,0)?"" : " not");

return 0;

}