C# Math.Tan() – Examples

In this tutorial, we will learn about the C# Math.Tan() method, and learn how to use this method to find the tangent of given angle, with the help of examples.

Tan(Double)

Math.Tan(a) returns the tangent of the specified angle a. Tan() function considers the specified angle in radians.

Syntax

The syntax of Tan() method is

</>
Copy
Math.Tan(Double a)

where

ParameterDescription
aThe angle in radians.

Return Value

The method returns double value.

Example 1 – Tan(45 degrees)

In this example, we will compute tangent for 45 degrees. We know that tan(45 degrees) is 1.

C# Program

</>
Copy
using System;

class Example {
    static void Main(string[] args) {
        Double angle = Math.PI/4; //45 degrees

        Double value = Math.Tan(angle);
        Console.WriteLine($"Tangent ({(180 / Math.PI) * angle} degrees) = {value}");
    }
}

Output

Tangent (45 degrees) = 1

Example 2 – Tan(60 degrees)

In this example, we will compute tangent for 60 degrees. We know that tan(45 degrees) is square root 3.

C# Program

</>
Copy
using System;

class Example {
    static void Main(string[] args) {
        Double angle = Math.PI/3; //60 degrees

        Double value = Math.Tan(angle);
        Console.WriteLine($"Tangent ({(180 / Math.PI) * angle} degrees) = {value}");
    }
}

Output

Tangent (60 degrees) = 1.73205080756888

Example 3 – Tan(0 degrees)

In this example, we will compute tangent for 0 degrees. We know that tan(0 degrees) is 0.

C# Program

</>
Copy
using System;

class Example {
    static void Main(string[] args) {
        Double angle = 0; //0 degrees

        Double value = Math.Tan(angle);
        Console.WriteLine($"Tangent ({(180 / Math.PI) * angle} degrees) = {value}");
    }
}

Output

Tangent (0 degrees) = 0

Example 4 – Tan(90 degrees)

In this example, we will compute tangent for 90 degrees. We know that tan(90 degrees) is Positive Infinity.

C# Program

</>
Copy
using System;

class Example {
    static void Main(string[] args) {
        Double angle = Math.PI/2; //90 degrees

        Double value = Math.Tan(angle);
        Console.WriteLine($"Tangent ({(180 / Math.PI) * angle} degrees) = {value}");
    }
}

Output

Tangent (90 degrees) = 1.63312393531954E+16

Example 5 – Tan(-60 degrees)

In this example, we will compute tangent for -60 degrees. We know that tan(-60 degrees) is negative of square root 3.

C# Program

</>
Copy
using System;

class Example {
    static void Main(string[] args) {
        Double angle = - Math.PI/3; //-60 degrees

        Double value = Math.Tan(angle);
        Console.WriteLine($"Tangent ({(180 / Math.PI) * angle} degrees) = {value}");
    }
}

Output

Tangent (-60 degrees) = -1.73205080756888

Conclusion

In this C# Tutorial, we have learnt the syntax of C# Math.Tan() method, and also learnt how to use this method with the help of C# example programs.