Math.Tan() Method in C#


The Math.Tan() method in C# is used to return the tangent of the specified angle.

Syntax

Following is the syntax −

public static double Tan (double val);

Here, Val is the angle.

Example

Let us now see an example to implement Math.Tan() method −

using System;
public class Demo {
   public static void Main(){
      double val1 = 30.0;
      Console.WriteLine(Math.Tan( (val1 * (Math.PI)) / 180 ));
   }
}

Syntax

This will produce the following output −

0.577350269189626

Example

Let us see another example to implement Math.Tan() method −

using System;
public class Demo {
   public static void Main(){
      double val1 = 45.0;
      double val2 = Double.PositiveInfinity;
      double val3 = Double.NaN;
      Console.WriteLine(Math.Tan( (val1 * (Math.PI)) / 180 ));
      Console.WriteLine(Math.Tan(val2));
      Console.WriteLine(Math.Tan(val3));
   }
}

Output

This will produce the following output −

1
NaN
NaN

Updated on: 06-Nov-2019

186 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements