To take the cosine of a number in Go programming language, we use the math.Cos()
function. This function takes a float64
type argument and returns its cosine value as a float64
type value.
Here is an example code snippet that shows how to use the math.Cos()
function in Go:
main.go215 chars15 lines
Output:
main.go17 chars2 lines
In the above code, we first import the math
package to access the Cos()
function. Then, we define an angle variable angle
and set its value to math.Pi / 2
, which is 90
degrees in radians. We then pass this angle
value to the math.Cos()
function, which returns its cosine value as cosine
. Finally, we print the angle
and cosine
values using fmt.Printf()
function.
gistlibby LogSnag