+ 1
Can someone help me again
Can anyone solve how to code these test A number's factorial is the product of all positive integers less than or equal to the number. Write a program that takes a number as input and outputs its factorial to the console. Sample Input 5 Sample Output 120 Explanation 5*4*3*2*1 = 120
15 odpowiedzi
+ 3
fix the bugs, edit the code, and show what you've got
+ 2
you have a syntax error after the parentheses in the for condition - after the parentheses should go immediately curly. think about the loop condition. why do you have the factorial variable equal to one and you compare the unit with the input value of number. think about whether the loop will be executed if number is equal to five? and you don't do anything with the factorial variable in the loop. once again, you write a program to calculate the product of all the numbers sequentially. product means multiplication
+ 2
after fixing the errors, your code will not be perfect yet, but suddenly you will succeed. I redid it and it worked. although I also solved this problem for a long time
+ 2
*I tried to solve it for a long time
+ 2
Darren Ardhianata
import math as m
print(m.factorial(5))
I know you seem a beginner
But this code will work
If you want a explaination
Ask me
+ 1
Hi! Please, for better help, show us your code attempt first!
+ 1
it's not java, it's javascript. please do not confuse them. they are completely two different languages. insert your code into the coding pad by selecting "web" and the "js" section
+ 1
Thank you i got it now
0
Oh
0
There
0
It should like this
fact=1
for(i=2;i<=n;i++)
fact=fact*i
print(fact)
It is just algorithm not in any language you can convert it into any language you want
and also n=the number for which you want to calculate factorial
0
And also print statement is outside for loop
- 1
I think above 👆 code will help u