.Cos()
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:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn C# on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn C#
Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.Beginner Friendly23 hours