I got this function that calculates factorial given an integer number:
long iterFact(long number) {
long factorial = 1;
for (long i = 1; i <= number; i++)
factorial *= i;
return factorial;
}
But it returns a negative number when I pass for example 20
as a parameter, I thought it would be because the number gets too long, but I'm still getting a negative number as result even after changing everything from int
to long
.