What is Math.cos() in C#?

C# has a built-in Math class that provides useful mathematical functions and operations. The Math class has the Cos() function, which is used to compute the cosine of a specified angle.

Syntax

public static double Cos (double value);

Parameters

  • value: value is of the Double type and represents the input angle for which we have to find Cos(). Its range is all real numbers. value is measured in radians.

Return value

  • Double: Cos() returns the cosine of a number; its type is Double. It is true only for all real numbers in value.
  • NaN: Cos() returns NaN type for invalid value, i.e., NaN, infinity, or negative infinity.

Degrees can be converted into radians by multiplying degrees by Math.PI/180.

Example

using System;
class Educative
{
static void Main()
{
double result = Math.Cos(0);
System.Console.WriteLine("Cos(0) = "+ result);
double result1 = Math.Cos(1);
System.Console.WriteLine("Cos(1) = "+ result1);
double result2 = Math.Cos(-1);
System.Console.WriteLine("Cos(-1) = "+ result2);
double result3 = Math.Cos(Double.PositiveInfinity);
System.Console.WriteLine("Cos(∞) = "+ result3);
double result4 = Math.Cos(400);
System.Console.WriteLine("Cos(400) = "+ result4);
}
}

Free Resources