Mike Johnson wrote: > Plesae rite a program for me to find prime nummers. It should be recursive > prorgram. What duz that mean? > If u type a nummer like 10 it should say "1 is prime, 2 is prime, 3 is prime, > 4 is not prime" up to 10. > This iz not homewurk I just thout of it myself. Lol.
/* Sure Mike, 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 t) { int r; if (t) return d?1+_(n,m,d-1,d):n?_(n-1,m,m,n):0; for(r=m!=n; d*(t<n); ++t) r &= _(n,_(t,m,0,1),d-1,0)|!_(t,1,t,0); return r*n; } /*------------------------------------------ Print primes up to the requested value --------------------------------------------*/ int main(int argc, char* argv[]) { int max; scanf("%d", &max); for(int n = 2; n <= max; n++) printf("%d is%s prime\n",n, _(n,1,n,0)?"":" not"); return 0; } -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.