Math.Cos() Method in C#


The Math.Cos() method in C# is used to return the cosine of the angle set as a parameter.

Syntax

Following is the syntax −

public static double Cos (double val);

Above, Val is the angle.

Example

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

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

Output

This will produce the following output −

0.866025403784439

Example

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

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

Output

This will produce the following output −

1
6.12303176911189E-17
raja
Published on 08-Nov-2019 10:55:18
Advertisements