![]() |
Given a radian value, our task is to find a tangent using JavaScript. Tangent (tan) is a trigonometric function which is the ratio of the length of the side opposite to an angle to the length of the adjacent side in a right triangle. Example: Input: 45 degrees Below are the approaches to find the tangent of a given radian value using JavaScript: Table of Content Using Math.tan() FunctionCreate a function that takes a radian parameter. Inside the function, use the Math.tan() function provided by JavaScript’s Math object to calculate the tangent of the given radian value. Return the calculated tangent value. Example: The example below shows finding the tangent of a given radian value Using Math.tan() Function.
Output Tangent of 60 radians is: 0.320040389379563 Time complexity: O(1). Space complexity: O(1). Using Trigonometric FormulaCreate a function that takes a radian parameter. Inside the function, use the Math.sin() function to calculate the sine of the given radian value and use the Math.cos() function to calculate the cosine of the radian value. Divide the sine value by the cosine value to obtain the tangent of the given radian value. Return the calculated tangent value. Example: The example below shows finding the tangent of a given radian value Using Math.tan() Function.
Output Tangent of 45 radians is: 1.6197751905438615 Time complexity: O(1). Space complexity: O(1). |
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |