about | help | code help+videos | done | prefs |
test2024_03_12_HL_factorialLike
For this problem you will write a method that computes something LIKE the factorial of a number, but it is not quite the same as a factorial. As you may know, 5!=5*4*3*2*1=120, and 6!=6*5*4*3*2*1=720. But we are NOT doing factorials! Instead, we are doing something "factorial like". For simplicity, lets define the symbols: "!~" to represent our mathematical operation that is "factorial like". Our 'factorialLike' method will return the result of the following recursively defined procedure: if n<=1 n!~=1. If n>1 n!~=n*((n-1)!~)+n. For example 3!~ = 3*(2!~)+3 = 3*(2*(1!~)+2)+3 = 3*(2*(1)+2)+3 = 15 You MAY choose to use recursion to solve this problem, but recursion is NOT required! You may also use one or more helper methods. Remember to make sure each method has only one return statement. NOTE: Your solution only needs to work for answers that are less than MaxInt. If the answer exceeds MaxInt, your solution can produce an error, strange results, or whatever. Input values that would produce results greater than MaxInt will NOT be tested! test2024_03_12_HL_factorialLike(8) → 109600 test2024_03_12_HL_factorialLike(4) → 64 test2024_03_12_HL_factorialLike(9) → 986409 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 430
Copyright Nick Parlante 2017 - privacy