Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,639 questions

55,374 answers

573 users

How to calculate a = e*(a+b*c+cos(d) where a,b,c,d are arrays of equal length and e is a scalar in Go

1 Answer

0 votes
package main
 
import (
    "fmt"
    "math"
)
 
func calculateFormula(a, b, c, d []float64, e float64) {
    for i, v := range a {
        a[i] = e * (v + b[i] * c[i] + math.Cos(d[i]))
    }
}
 
func main() {
    a := []float64{1.0, 2.0, 3.0, 4.0}
    b := []float64{3.1, 2.5, 8.3, 4.6}
    c := []float64{7.0, 8.0, 9.0, 10.0}
    d := []float64{11.0, 12.0, 0.0, 15.0}
    e := 7.0
 
    calculateFormula(a, b, c, d, e)
    fmt.Println("After calculation: ", a)
}
 
 
 
/*
run:
 
After calculation:  [158.93097988591634 159.90697771112744 550.9 344.6821846099882]

*/

 



answered Jul 1, 2025 by avibootz
edited Jul 1, 2025 by avibootz
...