Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top