In Go, you can use the math
package to calculate the sine, cosine, and tangent of an angle. Here's an example code snippet to demonstrate how to do it:
package main
import (
"fmt"
"math"
)
func main() {
angle := 45.0 // angle in degrees
// Convert the angle to radians
radians := angle * math.Pi / 180.0
// Calculate the sine, cosine, and tangent of the angle
sine := math.Sin(radians)
cosine := math.Cos(radians)
tangent := math.Tan(radians)
// Print the results
fmt.Printf("Sine: %.2f\n", sine)
fmt.Printf("Cosine: %.2f\n", cosine)
fmt.Printf("Tangent: %.2f\n", tangent)
}
In this example, we first convert the angle from degrees to radians by multiplying it with math.Pi / 180.0
. Then, we use math.Sin()
, math.Cos()
, and math.Tan()
functions from the math
package to calculate the respective trigonometric values. Finally, we use fmt.Printf()
to print the results with two decimal places.