Calculating factorial of large numbers in C

No standard C data type will accurately handle numbers as large as 100!. Your only option if to use arbitrary precision integer arithmetic, either through a library or done by yourself.

If this is just some hobby project, I’d suggest trying it yourself. It’s kind of a fun exercise. If this is work-related, use a pre-existing library.

The largest C data type you’ll normally get is a 64-bit integer. 100! is in the order of 10157, which takes at least 525 bits to store accurately as an integer.

Leave a Comment