C# .Acos()

chip3115849932's avatar
Published Mar 13, 2023Updated May 19, 2023
Contribute to Docs

The Math.Acos() method returns the absolute value of the inverse cosine of the argument, measured in radians. In other words, it returns the positive angle whose cosine is the specified number.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.
    • Beginner Friendly.
      15 hours

Syntax

Math.Acos(x);

The method takes one parameter x of the type double. It will return a positive value of type double except in the following cases:

  • If x is less than -1, it will return NaN (not a number).
  • If x is greater than 1, it will return NaN.
  • If x is NaN, it will return NaN.

Example

The following example prints the results of the Math.Acos() method for five different values.

using System;
namespace MyMathExample
{
public class Example
{
public static void Main(string[] args)
{
double a = Math.Acos(0.5);
double b = Math.Acos(1);
double c = Math.Acos(-2);
double d = Math.Acos(4);
double e = Math.Acos(0);
Console.WriteLine(a);
Console.WriteLine(b);
Console.WriteLine(c);
Console.WriteLine(d);
Console.WriteLine(e);
}
}
}

This results in the following output:

1.0471975511966
0
NaN
NaN
1.5707963267949

Codebyte Example

The example below uses Math.Acos() to calculate the arc cosine of x. The result is stored in the result variable.

Code
Output

All contributors

Contribute to Docs

Learn C# on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.
    • Beginner Friendly.
      15 hours