- 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 37 times
Consider the following Java program to calculate the factorial of a number n (factorial of n or n! is defined as product
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Consider the following Java program to calculate the factorial of a number n (factorial of n or n! is defined as product
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; }