سؤال

My code:

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

output 2.0 10.0

Expected output 2.0000000000 10.0000000000

هل كانت مفيدة؟

المحلول

If you just want to print extra decimal places you can try:

puts "%.8f" %p

or

sprintf "%.8f" %p

where 8 means eight decimal places.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top