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.rb91 chars7 lines
The output is the tangent of the given number 45
, which is approximately 1.6198
.
gistlibby LogSnag