.Cos()

cslylla's avatar
Published Mar 25, 2023
Contribute to Docs

The Math.Cos() class method returns the cosine of a given angle.

Syntax

Math.Cos(angle);

The Math.Cos() method takes only one parameter, angle, an angle in radians of type double. The method returns the cosine of the angle as a double value or NaN (not a number) if the value of angle equals:

  • NaN
  • NegativeInfinity
  • PositiveInfinity

Example

The following example first converts 60 degrees to radians, then uses the Math.Cos() method to return the sine of that angle. Finally, the Console.WriteLine() function prints the result to the console:

using System;
public class Example {
public static void Main(string[] args) {
double degrees = 60;
double radians = degrees * Math.PI/180;
double cosine = Math.Cos(radians);
Console.WriteLine("The cosine of " + degrees + " degrees is: " + cosine);
}
}

The example will result in the following output:

The cosine of 60 degrees is: 0.5

Codebyte Example

The following example is runnable and returns the cosine of the angle given in degrees:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn C# on Codecademy