Factorial of larger no like 100 etc

In normal procedure of loops the factorial value is displayed for 20 factorial but in recursion it shows a negative no !! why ?? and how should i find the factorial of a larger no like 100.

@Krish-Banerjee-2770813363035183,
We use bigInteger for that. Since integer/long will overflow and return garbage values.

public static void main(String[] args) {

BigInteger fact = BigInteger.valueOf(1);
for (int i = 1; i <= 100; i++)
    fact = fact.multiply(BigInteger.valueOf(i));
System.out.println(fact);
}

I have attached the code for the same.

BigInteger:
BigInteger class is used for mathematical operation which involves very big integer calculations that are outside the limit of all available primitive data types.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like