C / C++ FAQs & Programming Resources - ProkutFAQ : BigNumFactorial

HomePage Recent Changes Recently Commented Login/Register
Quick Links
Categories
Links

How to find factorial of big numbers such as 100 or higher?


We can do it by implementing our own functions to perform multi-precision arithmetic, or just use any of the freely available libraries for multi-precision arithmetic like GNU Multiple Precision Arithmetic Library. GMP is a portable library. For installing this library in Windows compilers, read GMP Install Instruction for Windows Platform.

Below is a sample program to find factorial of 100 using the GNU MP library:
#include<stdio.h>
#include<gmp.h> //The GNU MP library header
int main()
{
unsigned long int n=100;
mpz_t fact;
mpz_init(fact);
mpz_fac_ui(fact, n); //Call the library function to find factorial
mpz_out_str(stdout,10,fact);//Print the result stored in fact
return 0;
}

References

GNU MP Online Documentation
 Comments [Hide comments/form]
Page was generated in 0.0245 seconds