0

factorising a number

is the following code correct for factorising a number https://code.sololearn.com/WHj1v9QPkzz1/?ref=app

18th Jun 2020, 9:03 AM
Msaligs
Msaligs - avatar
5 odpowiedzi
+ 2
Msaligs Yes this is correct and also you can get factorial using recursion like this function fact(num) { if(num == 0 || num == 1) { return 1; } return num * fact(num - 1); } console.log(fact(5))
18th Jun 2020, 9:25 AM
A͢J
A͢J - avatar
+ 1
Yes I think it's correct!
18th Jun 2020, 9:20 AM
Hacker Badshah
Hacker Badshah - avatar
+ 1
This logic is to find the factorial of a number. Factorial of a number is the product from 1 to the number itself. For example: Factorial of 5 is 1*2*3*4*5=120.
18th Jun 2020, 9:22 AM
Souptik Nath
Souptik Nath - avatar
+ 1
Yes it is but what about negative values ? How to calculate the factorial for negatives??? https://code.sololearn.com/WuQ38sIic7Ro/?ref=app
18th Jun 2020, 9:25 AM
Ahmed Shoáib
Ahmed Shoáib - avatar
0
Yup
18th Jun 2020, 9:25 AM
Abhay
Abhay - avatar