Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.