| An iterative Factorial function. | Lecture 9 - slide 5 : 30 Program 1 |
public static BigInteger Factorial(int n){
if (n >= 0){
BigInteger res = 1;
for(int i = 1; i <= n; i++)
res = res * i;
return res;
}
else throw new ArgumentException("n must be non-negative");
} |