C# | Math.Cos() Method
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 csoine 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.
// C# program to demonstrate working // Math.Cos() method using System; class Geeks { // Main Method public static void Main(String []args) { double a = 70; // converting value to radians double b = (a * (Math.PI)) / 180; // using method and displaying result Console.WriteLine(Math.Cos(b)); a = 50; // converting value to radians b = (a * (Math.PI)) / 180; // using method and displaying result Console.WriteLine(Math.Cos(b)); a = 73; // converting value to radians b = (a * (Math.PI)) / 180; // using method and displaying result Console.WriteLine(Math.Cos(b)); a = 77; // converting value to radians b = (a * (Math.PI)) / 180; // using method and displaying result Console.WriteLine(Math.Cos(b)); } } |
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.
// C# program to demonstrate working // Math.Cos() method in infinity case using System; class Geeks { // Main Method public static void Main(String []args) { double positiveInfinity = Double.PositiveInfinity; double negativeInfinity = Double.NegativeInfinity; double nan = Double.NaN; double result; // Here argument is negative infinity, // output will be NaN result = Math.Cos(negativeInfinity); Console.WriteLine(result); // Here argument is positive infinity, // output will also be NaN result = Math.Cos(positiveInfinity); Console.WriteLine(result); // Here argument is NaN, output will be NaN result = Math.Cos(nan); Console.WriteLine(result); } } |
NaN NaN NaN
Recommended Posts:
- Difference between Method Overriding and Method Hiding in C#
- C# | IsNullOrEmpty() Method
- C# | Uri.IsBaseOf(Uri) Method
- C# | Uri.FromHex() Method
- C# | Replace() Method
- C# | Join Method | Set - 2
- Stack.Contains() Method in C#
- C# | Method Parameters
- C# | Insert() Method
- C# | Random.Next() Method
- C# | Uri.IsHexDigit() Method
- C# | IndexOfAny() Method
- C# | String.Contains() Method
- C# | Remove() Method
- C# | Math.Tan() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



