I\'ve been trying to make a factorial function in C++, and I just found that inputs which are greater than 10 are not calculated correctly. I tried C# but I faced the same probl
That's because int
is limited to 32 bits, and results of 10!
much beyond 10 will give you a bigger result. For larger values, you can get an approximate result using double
as the result. If you want more than about 16 digits precision, you need to use a multiprecision math library.
Using uint64_t
would allow a larger number, but still fairly limited.