# Is there any built-in factorial function in c++?

## Is there any built-in factorial function in c++?

Although there is no C function defined specifically for computing factorials, C math library lets you compute gamma function. Since Г(n) = (n-1)! for positive integers, using `tgamma`

of `i+1`

yields `i!`

.

If you use a user-defined factorial function, this would print identical numbers:

```
for (int i = 1 ; i != 10 ; i++) {
printf(%lld %fn, factorial(i), tgamma(i+1));
}
```

```
1 1.000000
2 2.000000
6 6.000000
24 24.000000
120 120.000000
720 720.000000
5040 5040.000000
40320 40320.000000
362880 362880.000000
```

**Note:** Considering how easy it is to code up factorial function, using gamma to compute factorials is a lot like killing a fly with a sledgehammer.

No, there is no such function in the Standard Library.

#### Is there any built-in factorial function in c++?

No, in standard c++ , there is no such function as factorial ,But you can find same functionality in boost library : `boost::math::factorial`