factorial of a number

前端 未结 28 2416
滥情空心
滥情空心 2020-12-09 11:57

I have the following code but it is not giving perfect result for factorial can u find it out plz



        
28条回答
  •  独厮守ぢ
    2020-12-09 12:42

    The important part of the function is this line:

     x = x * fact(x-1);
    

    but the fact function does not return a value, so this is the same as x * undefined. Try adding return x; to the bottom of your function.

提交回复
热议问题