C MathTan 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.

TanDouble

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

Math.Tan(Double a)

where

Parameter Description
a The angle in radians.

Return Value

The method returns double value.

Example 1 Tan45 degrees

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

C# Program

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 Tan60 degrees

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

C# Program

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 Tan0 degrees

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

C# Program

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 Tan90 degrees

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

C# Program

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

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.