Try n=100 as input in your you will get this!!!
Basically, 100! is a large value and can’t be stored in int data type, In fact 17! will come out to be negative if you try.
This is because long long cannot handle answer as large as 100!. It has digits more than 157 which is clearly out of range of long long. Now you can do this in two ways-
- The most obvious way is to use strings.
- A library named boost multiprecision is present in C++, which has a very high range and can handle these value. To know more, check this link- https://www.geeksforgeeks.org/advanced-c-boost-library/