How to calculate factorial in ruby -


this question has answer here:

question :

input:   4 # number of input    1   2   4   3 output:   1   2   24   6 

cannot desired output

my code: num  = integer(gets.chomp) k = [] in 1..num k[i] = integer(gets.chomp) end  k.each |w| in 1..w w.to_i = w*i end puts w  end 

you can try like:

input = integer(gets.chomp)  ans = 1 in 1..input  ans = ans*i end print(ans) 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -