Help, What part of the code should I modify? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help, What part of the code should I modify?

The code has no output when I enter the value 15, 20, and 25 in parameter 1 https://code.sololearn.com/cneH702wD1y1/?ref=app

20th Mar 2022, 2:57 PM
Edward
6 Answers
+ 1
Presently, the code is computing n!*20, and doing it by addition via tail recursion. Fortunately, it is not too hard to convert repeated addition into multiplication, and from tail recursion into a simple loop. However, in this case I would not even try a conversion. I think it would be easier just to write a factorial-calculating loop. Then multiply the result by 20.
21st Mar 2022, 6:34 AM
Brian
Brian - avatar
+ 1
It accepting.. Do you mean about no output?
20th Mar 2022, 4:49 PM
Jayakrishna 🇮🇳
0
Yes, there is no output when I enter the value 15, 20, and 25 in my method factorial
20th Mar 2022, 5:06 PM
Edward
0
What are you trying by the factorial method? Oh..You are making recursion 300+ calls for input sample 5. Above 10 input, you are getting sololearn execution timeout. What is value 20 there?
20th Mar 2022, 6:49 PM
Jayakrishna 🇮🇳
0
Edward it is very likely that the program is blowing up the stack. With 15 as input, your factorial function is attempting 2,615,348,736,000 recursive calls. You might want to revamp the algorithm.
20th Mar 2022, 7:10 PM
Brian
Brian - avatar
0
Is there any way to fix the problem?
21st Mar 2022, 6:00 AM
Edward