You are viewing a single comment's thread. Return to all comments →
My solution in golang
package main import ( "fmt" ) func main() { var n int var a []int n = readNumber() for i:=1; i <= n; i++ { n_t := readNumber() a = append(a, n_t) } var positive []int var negative []int var zero []int for _, v := range a { if v > 0 { positive = append(positive, v) } else if v < 0 { negative = append(negative, v) } else if v == 0 { zero = append(zero, v) } } //fmt.Sprintf("%.2f", len(positive) / n) fmt.Printf("%f\n", float32(len(positive))/float32(n)) fmt.Printf("%f\n", float32(len(negative))/float32(n)) fmt.Printf("%f\n", float32(len(zero))/float32(n)) } func readNumber() int { var n int _, err := fmt.Scanf("%d", &n) if err != nil { panic(err) } return n }
Seems like cookies are disabled on this browser, please enable them to open this website
Plus Minus
You are viewing a single comment's thread. Return to all comments →
My solution in golang