# Finding Sine Value of Specified Number in Golang

In mathematics, the sine function is a trigonometric function that represents the ratio of the length of the side opposite to an angle to the length of the hypotenuse in a right-angled triangle. It is denoted by sin. In Golang, the math package provides the Sin() function that returns the sine value of a given number in radians.

## Syntax

The syntax for finding the sine value of a specified number in Golang is −

func Sin(x float64) float64


Where x is the angle in radians.

## Example 1: Find Sine Value of 0.5

Let's write a program that finds the sine value of 0.5 using the Sin() function.

package main

import (
"fmt"
"math"
)

func main() {
x := 0.5
sin := math.Sin(x)
fmt.Printf("The sine value of %f is %f\n", x, sin)
}


## Output

The sine value of 0.500000 is 0.479426


## Example 2: Find Sine Value of π

Let's write a program that finds the sine value of π (pi) using the Sin() function.

package main

import (
"fmt"
"math"
)
func main() {
x := math.Pi
sin := math.Sin(x)
fmt.Printf("The sine value of %f is %f\n", x, sin)
}


## Output

The sine value of 3.141593 is 0.000000


## Example 3: Find Sine Values of Multiple Numbers

Let's write a program that finds the sine values of multiple numbers using the Sin() function.

package main

import (
"fmt"
"math"
)

func main() {
numbers := []float64{0.1, 0.2, 0.3, 0.4, 0.5}
for _, x := range numbers {
sin := math.Sin(x)
fmt.Printf("The sine value of %f is %f\n", x, sin)
}
}


## Output

The sine value of 0.100000 is 0.099833
The sine value of 0.200000 is 0.198669
The sine value of 0.300000 is 0.295520
The sine value of 0.400000 is 0.389418
The sine value of 0.500000 is 0.479426


## Conclusion

The Sin() function provided by the math package in Golang makes it easy to find the sine value of a given number in radians. In this article, we covered the syntax for the Sin() function and provided three examples of how to use it to find the sine values of single and multiple numbers.

Updated on: 12-Apr-2023

47 Views