Math.Acos() Method in C#


The Math.Acos() method in C# returns the angle whose cosine is the specified number. This number is a double value argument. 

Syntax

The syntax is as follows −

public static double Acos (double val);

Above, Val is the number representing a cosine, where Val must be greater than or equal to -1, but less than or equal to 1.

Example

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

using System;
public class Demo {
   public static void Main(){
      double val1 = -0.0;
      double val2 = Double.PositiveInfinity;
      double val3 = Double.NaN;
      Console.WriteLine("Return value of {0} : {1}", val1, Math.Acos(val1));
      Console.WriteLine("Return value of {0} : {1}", val2, Math.Acos(val2));
      Console.WriteLine("Return value of {0} : {1}", val2, Math.Acos(val3));
   }
}

Output

This will produce the following output −

Return value of 0 : 1.5707963267949
Return value of ∞ : NaN
Return value of ∞ : NaN

Example

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

using System;
public class Demo {
   public static void Main(){
      double val1 = -30.0;
      double val2 = 30.0;
      double val3 = 0;
      Console.WriteLine("Return value of {0} : {1}", val1, Math.Acos(val1));                               Console.WriteLine("Return value of {0} : {1}", val2, Math.Acos(val2));
      Console.WriteLine("Return value of {0} : {1}", val2, Math.Acos(val3));
   }
}

Output

This will produce the following output −

Return value of -30 : NaN
Return value of 30 : NaN
Return value of 30 : 1.5707963267949
raja
Published on 06-Nov-2019 05:53:18
Advertisements