take the tangent of a number in ruby

Ruby provides the Math module that exposes various trigonometric functions including the tangent function. To take the tangent of a number in Ruby, first ensure that you have required the Math module by calling require 'math'. Then use the Math.tan(x) method where x is the number for which you want to find the tangent.

main.rb
require 'math'

number = 45
tangent = Math.tan(number)

puts tangent  # 1.6197751905438615
91 chars
7 lines

The output is the tangent of the given number 45, which is approximately 1.6198.

related categories

gistlibby LogSnag