Is there any built-in factorial function in c

0 votes
Despite my search, I was unable to locate this.

Would someone kindly let me know whether there is a factorial function integrated into C++?
Aug 1, 2022 in C++ by Nicholas
• 7,760 points
10,642 views

1 answer to this question.

0 votes

Although no C function is written particularly for computing factorials, the C math package allows you to compute the gamma function. Because (n) Equals (n-1)! 

Using tgamma of i+1 on positive integers returns i!.

for (int i = 1 ; i != 10 ; i++) {
    printf("%lld %f\n", factorial(i), tgamma(i+1));
}

Demo.

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
answered Aug 2, 2022 by Damon
• 4,960 points

Related Questions In C++

0 votes
1 answer

What data structure is inside std::map in C++?

An associative container is std::map. The standard's ...READ MORE

answered May 31, 2022 in C++ by Damon
• 4,960 points
1,365 views
0 votes
0 answers

What is the C++ function to raise a number to a power?

What's the best way to raise a n ...READ MORE

Jun 1, 2022 in C++ by Nicholas
• 7,760 points
852 views
0 votes
1 answer

Function default argument value depending on argument name in C++ [duplicate]

When the function is called with no argument for the corresponding parameter, the default argument is evaluated.  In a default argument, a parameter must not appear as a potentially evaluated expression.  A function's parameters declared before a default argument are in scope and can obscure the namespace and class member name. It provides the following example: int h(int a, ...READ MORE

answered Jun 7, 2022 in C++ by Damon