User:Whoblah/Ruby/Math

Solutions to simple math problems using Ruby


 * 1) !/usr/bin/env ruby
 * 2) Area of a circle

def area_circle(radius) return Math::PI * (radius)**2 end

puts "What is the radius of the circle?" input = gets.chomp.to_f area = area_circle(input).to_f puts "The radius of the circle is #{input} units" puts "The area of the circle is #{area} square units"


 * 1) !/usr/bin/env ruby
 * 2) Area of an octagon

def area_octagon(radius) return 2 * (radius)**2 * Math::sqrt(2) end

puts "What is the radius of the octagon?" input = gets.chomp.to_f area = area_octagon(input).to_f puts "The radius of the octagon is {#input} units" puts "The area of the octagon is {#area} square units"