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

One recursion to loop them all

Name: Anonymous 2011-04-01 11:52

Why do you need any loop constructs if you have recursion

Name: Anonymous 2011-04-01 17:18

>>9

long fact (long x) {
  long r = 1;
  while (x) r *= x--;
  return r;
}
long fact_rec (long x, long r) {
  return x? fact_rec(x-1,x*r) : r;
}

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