C# Math.Cos() – Examples

In this tutorial, we will learn about the C# Math.Cos() method, and learn how to use this method to find the cosine of given angle, with the help of examples.

Cos(Double)

Math.Cos(a) returns the cosine of the specified angle a. Cos() function considers the specified angle in radians.

Syntax

The syntax of Cos() method is

</>
Copy
Math.Cos(Double a)

where

ParameterDescription
aThe angle in radians.

Return Value

The method returns double value.

Example 1 – Cos(45 degrees)

In this example, we will compute cosine for 45 degrees. We know that cos(45 degrees) is inverse of square root 2.

C# Program

</>
Copy
using System;

class Example {
    static void Main(string[] args) {
        Double angle = Math.PI/4; //45 degrees

        Double value = Math.Cos(angle);
        Console.WriteLine($"Cosine ({(180 / Math.PI) * angle} degrees) = {value}");
    }
}

Output

Cosine (45 degrees) = 0.707106781186548

Example 2 – Cos(90 degrees)

In this example, we will compute cosine for 90 degrees. We know that cos(90 degrees) is 0.

C# Program

</>
Copy
using System;

class Example {
    static void Main(string[] args) {
        Double angle = Math.PI/2; //90 degrees

        Double value = Math.Cos(angle);
        Console.WriteLine($"Cosine ({(180 / Math.PI) * angle} degrees) = {value}");
    }
}

Output

Cosine (90 degrees) = 6.12323399573677E-17

6.12323399573677E-17 is very very near to zero. This can be considered zero until the precision of 16 digits after decimal.

Example 3 – Cos(-60 degrees)

In this example, we will compute cosine for -60 degrees. We know that cos(-60 degrees) is 0.5

C# Program

</>
Copy
using System;

class Example {
    static void Main(string[] args) {
        Double angle = Math.PI/3; //-60 degrees

        Double value = Math.Cos(angle);
        Console.WriteLine($"Cosine ({(180 / Math.PI) * angle} degrees) = {value}");
    }
}

Output

Cosine (60 degrees) = 0.5

Conclusion

In this C# Tutorial, we have learnt the syntax of C# Math.Cos() method, and also learnt how to use this method with the help of C# example programs.