It is giving t correct outputs for small numbers. See this: link

BTW you are getting Wrong Ans because of maximum limit of int. Even if you use unsigned long long int, you will not be able to calculate factorial(100). This is because of overflow. i.e, size of the variable is exceeding the maximum permitted size.

Follow this link for calculating the factorial of numbers >=20 link