Skip to content

Instantly share code, notes, and snippets.

@kharioki
Created September 28, 2016 19:23
Show Gist options
  • Save kharioki/bc298bc1b25a28cf15f197ae7496b646 to your computer and use it in GitHub Desktop.
Save kharioki/bc298bc1b25a28cf15f197ae7496b646 to your computer and use it in GitHub Desktop.
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