Consider the following Java program to calculate the factorial of a number n (factorial of n or n! is defined as product
-
answerhappygod
- Site Admin
- Posts: 899604
- 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; }
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!