std factorial function

Is there a factorial function defined in a header file someplace in *nix or c/c++
I don't want to have to write this anytime i need it, kind of annoying

all googles report a bunch of noobie problems
Nope. At least, not as far as I know of. If anywhere, it would be in <cmath>, but I didn't see it there.

You can write your own function and copy it to a file where you can easily find it, though!

-Albatross
Last edited on
A simple factorial functions requires two lines, is it that much to write?
I mean isn't that the point of a function...
I realized that i actually needed nCm.
I actually can't recall anytime I have actually needed to compute a factorial besides class assignments.
Perhaps this is why it's not in a standard header and Bazzy's point is quite valid.
A simple factorial functions requires two lines, is it that much to write?


Nope, a simple factorial (such as, for example, 25!), takes more than 64 bits of space when represented as a number. So, even simple factorials such as 25! are not that easy to realize.
I'm talking about function implementation.
Even a + operation may give too large results. This doesn't mean that addition is not a trivial operation.
2-lines function is 2-lines function
closed account (1yR4jE8b)
1
2
3
4
int factorial(int n)
{
  return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n;
}


*ahem*
Single-liner! :^(
lol owned
Topic archived. No new replies allowed.