Skip to content

Instantly share code, notes, and snippets.

@pensebien
Created September 28, 2016 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pensebien/4798a40bf304648b8f9cad26a074eea2 to your computer and use it in GitHub Desktop.
Save pensebien/4798a40bf304648b8f9cad26a074eea2 to your computer and use it in GitHub Desktop.
puts "Enter a number to find the square"
number = gets.chomp.to_i
puts "Enter the accepted error"
error = gets.chomp.to_i
def abs(firstNum,secNum)
if firstNum>secNum
firstNum-secNum
else
puts "Why not work"
secNum - firstNum
end
end
def square (x)
x * x
end
def sqrt(x,d)
max = x/2.0
min = 0
mid = x/2.0
until square(mid)-x <=d and square(mid)-x >=d
mid = (max+min)/2
if square(mid)-x>0
max = mid
else
puts "I am in here"
min = mid
end
end
mid
end
puts sqrt(number,error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment