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

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -