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

Java Stream API - How to convert List of objects to another List of objects using Java streams?

Registration and Login with Spring Boot + Spring Security + Thymeleaf

Java, Spring Boot Mini Project - Library Management System - Download

ReactJS, Spring Boot JWT Authentication Example

Top 5 Java ORM tools - 2024

Java - Blowfish Encryption and decryption Example

Spring boot video streaming example-HTML5

Google Cloud Storage + Spring Boot - File Upload, Download, and Delete