Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的代码:
def cube_root(x) a = x**(1/3.0) p = a.ceil puts p end gets.chomp.to_i.times do q = gets.chomp.to_i cube_root(q) end
input 2 8 1000
input
output 2.0 10.0
output
预期产量 2.0000000000 10.0000000000
如果您只想打印额外的小数位,您可以尝试:
puts "%.8f" %p
或者
sprintf "%.8f" %p
其中 8 表示小数点后八位。