Created
September 28, 2016 19:23
-
-
Save kharioki/bc298bc1b25a28cf15f197ae7496b646 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
def mid_point(x,y) | |
(x+y)/2.0 | |
end | |
def square_root(x,e) | |
if x==1; | |
guess=1 | |
else | |
lowest = 0 | |
highest = x | |
guess = mid_point(lowest,highest) | |
range = (guess*guess)- x | |
until range <= e and range > 0 do | |
if range < 0 | |
lowest = guess | |
else highest = guess | |
end | |
guess = mid_point(lowest, highest) | |
range = (guess*guess)- x | |
end | |
guess | |
end | |
end | |
print "Enter No.:" | |
x = Float $stdin.gets.chomp() | |
print "Enter Haze No.:" | |
e = Float $stdin.gets.chomp() | |
puts "Th square root of #{x} is #{square_root(x,e)}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment