Page 1 of 1

Consider the following Java program to calculate the factorial of a number n (factorial of n or n! is defined as product

Posted: Sat Feb 19, 2022 3:20 pm
by answerhappygod
Consider The Following Java Program To Calculate The Factorial Of A Number N Factorial Of N Or N Is Defined As Product 1
Consider The Following Java Program To Calculate The Factorial Of A Number N Factorial Of N Or N Is Defined As Product 1 (29.65 KiB) Viewed 39 times
Consider the following Java program to calculate the factorial of a number n (factorial of n or n! is defined as product of number from 1 to n - 1x2x3x....x(n-1)xn. Factorial of 0 is 1 by definition). Determine the worst-case running time of the algorithm in terms of n. Clearly show how you obtained your answer. public static long factorial (int n) { if(n < 0) return -1; //Error long result = 1.0; for (int i=1; i<= n; i++) result *= i; return result; }