Created
September 28, 2016 19:03
-
-
Save pensebien/4798a40bf304648b8f9cad26a074eea2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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