C# .Acos()
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.
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
xis less than -1, it will returnNaN(not a number). - If
xis greater than 1, it will returnNaN. - If
xisNaN, it will returnNaN.
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.04719755119660NaNNaN1.5707963267949
Codebyte Example
The example below uses Math.Acos() to calculate the arc cosine of x. The result is stored in the result variable.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve 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