The factorial of a non-negative integer n, n!, is defined as the product of all positive integers less than or equal to n:
0! = 1
n! = 1×2×3×…×n
Find the bugs in the following code extract intended to compute the value of n!.
private int fact(int n){
int nf = 1;
for (int i = 1; i < n; ++i) {
nf *= i;
}
return nf;
}
Once this is complete, I must Re-write this function to remove the “for” loop.
Any suggestions is greatly appreciated!