C# | Math.Cos() Method
Last Updated :
11 Jan, 2022
Math.Cos() is an inbuilt Math class method which returns the cosine of a given double value argument(specified angle).
Syntax:
public static double Cos(double num)
Parameter:
num: It is the angle(measured in radian) whose cosine is to be returned and the type of this parameter is System.Double.
Return Value: Returns the cosine of num of type System.Double. If num is equal to NegativeInfinity, PositiveInfinity, or NaN, then this method returns NaN.
Below are the programs to illustrate the Math.Cos() method.
Program 1: To show the working of Math.Cos() method.
CSharp
using System;
class Geeks {
public static void Main(String []args)
{
double a = 70;
double b = (a * (Math.PI)) / 180;
Console.WriteLine(Math.Cos(b));
a = 50;
b = (a * (Math.PI)) / 180;
Console.WriteLine(Math.Cos(b));
a = 73;
b = (a * (Math.PI)) / 180;
Console.WriteLine(Math.Cos(b));
a = 77;
b = (a * (Math.PI)) / 180;
Console.WriteLine(Math.Cos(b));
}
}
|
Output:
0.342020143325669
0.642787609686539
0.292371704722737
0.224951054343865
Program 2: To show the working of Math.Cos() method when the argument is NaN or infinity.
CSharp
using System;
class Geeks {
public static void Main(String []args)
{
double positiveInfinity = Double.PositiveInfinity;
double negativeInfinity = Double.NegativeInfinity;
double nan = Double.NaN;
double result;
result = Math.Cos(negativeInfinity);
Console.WriteLine(result);
result = Math.Cos(positiveInfinity);
Console.WriteLine(result);
result = Math.Cos(nan);
Console.WriteLine(result);
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...