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:

Comments

Popular posts from this blog

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

ReactJS - Bootstrap - Buttons

Spring Core | BeanFactoryPostProcessor | Example

Spring Boot 3 + Spring Security 6 + Thymeleaf - Registration and Login Example

File Upload, Download, And Delete - Azure Blob Storage + Spring Boot Example

Custom Exception Handling in Quarkus REST API

ReactJS, Spring Boot JWT Authentication Example

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

Top 5 Java ORM tools - 2024

Java - DES Encryption and Decryption example