Skip to content

Instantly share code, notes, and snippets.

@ErikBoesen
Created October 13, 2016 15:23
Show Gist options
  • Save ErikBoesen/1530487206a0ffa71edc86ec1e50ecd6 to your computer and use it in GitHub Desktop.
Save ErikBoesen/1530487206a0ffa71edc86ec1e50ecd6 to your computer and use it in GitHub Desktop.
puts "What number do you want to get the square root of? "
x = gets.chomp.to_f
puts "What's your first guess? "
r = gets.chomp.to_f
puts "Calculating square root of #{x} with guess #{r}."
10.times do |i|
r = (r + x/r) / 2
puts "Closer answer: #{r}. Calculating more places..."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment