Trigonometry with Go Language - Sin, Cos, Tan Functions Examples

Package math provides functions to calculate Trigonometric functions values.

Program to demonstrate how to calculate Trigonometric functions values in Go,

package main

import (
"fmt"
"math"
)

func main() {

var degrees float64

fmt.Println("Enter value of angle in degrees : ")

_, err := fmt.Scanf("%f", &degrees)

if err != nil {
fmt.Println(err)
}

//calculate the sine
s := math.Sin(degrees)
fmt.Println("The Sine of ", degrees, " degrees is : ", s)

//calculate the cosine
c := math.Cos(degrees)
fmt.Println("The Cosine of ", degrees, " degrees is : ", c)

//calculate the tan
t := math.Tan(degrees)
fmt.Println("The Tangent of ", degrees, " degrees is : ", t)

//calculate the sec
se := 1 / math.Sin(degrees)
fmt.Println("The Sec of ", degrees, " degrees is : ", se)

//calculate the cosec
co := 1 / math.Cos(degrees)
fmt.Println("The Cosec of ", degrees, " degrees is : ", co)

//calculate the cotangent
cot := 1 / math.Tan(degrees)
fmt.Println("The Cotangent of ", degrees, " degrees is : ", cot)

}

Output:

Popular posts from this blog

Learn Java 8 streams with an example - print odd/even numbers from Array and List

Spring boot video streaming example-HTML5

Spring Boot + Mockito simple application with 100% code coverage

Spring Boot + OpenCSV Export Data to CSV Example

Custom Exception Handling in Quarkus REST API

Registration and Login with Spring Boot + Spring Security + Thymeleaf

DataTable-Pagination example with Spring boot, jQuery and ajax

Spring Webflux File Download - REST API Example

Node JS mini projects with source code - free download

ReactJS, Spring Boot JWT Authentication Example