#!/usr/koeki/bin/ruby #coding: euc-jp def func (x) return Math::sqrt(9 - x * x) end def trapezoid(x1, x2) n = 100.0 d = (x2 - x1) / n x = x1 s = 0 1.upto(n - 1) do |i| x += d s += func(x) end int = d * ((func(x1) + func(x2)) / 2 + s) end print "x_1: " a1 = gets.chomp.to_f print "x_2: " a2 = gets.chomp.to_f puts "(#{a1}, #{a2}): #{trapezoid(a1,a2)}"