.Tan()
Anonymous contributor
Published Apr 18, 2023Updated Nov 9, 2024
Contribute to Docs
In C#, the Math.Tan()
method returns the tangent of a given angle.
Syntax
Math.Tan(angle);
The Math.Tan()
method takes only one parameter, angle
, an angle in radians of type double
. The method returns the tangent of the angle
as a double
value or NaN
(not a number) if the value of angle
equals:
NaN
NegativeInfinity
PositiveInfinity
Example
The following example converts 30 degrees to radians and then uses the Math.Tan()
method to calculate the tangent of that angle. Finally, Console.WriteLine()
outputs the result to the console:
using System;public class Example {public static void Main(string[] args) {// Define an angle in degreesdouble degrees = 30;// Convert the angle to radiansdouble radians = degrees * Math.PI/180;// Calculate the tangent of the angledouble tangent = Math.Tan(radians);// Display the resultConsole.WriteLine("The tangent of " + degrees + " degrees is: " + tangent);}}
The above example will result in the following output:
The tangent of 30 degrees is: 0.5773502691896257
Codebyte Example
The following example is runnable and returns the tangent of the angle
given in degrees:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn C# on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn C#
Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.Beginner Friendly23 hours