I have wrote the following code, it works perfectly in my compiler but gives wrong answer on my submission;
using namespace std;
int my_func(int n)
Could anyone help me out!
100 factorial cannot be stored in any primitive data type in C and C++ . Check the constraints on n
Could you help me out to solve the problem recursively ?
In general, Its a humble request that please do check the problem you are facing on discussion forum search box…!
Whole discussion is present up here in this link: http://discuss.codechef.com/questions/59732/fctrl2codechef-says-giving-a-wrong-answer-while-the-program-is-perfectly-fineplease-help
As @acodebreaker2 100 factorial do not fits in any integer datatype since length of 100 factorial is of 158 numbers.
Go through with the above link you’ll get the detailed explanation up there…
EDIT: And do check this link of how to compute large factorials in c or c++
As you are using C++ you don’t have any default mechanisms to store large numbers as large as 100!(158 digits).
You can try using arrays by storing each digit of the number in a different index and modify the printing accordingly. Try to solve the problem using this approach If you still don’t get it you can always look other’s solution