Why does this code always return zero:
package main
import "fmt"
func main() {
var index_of_array int
fmt.Scan(&index_of_array)
var arr = make([]int, index_of_array)
for i := 0; i < len(arr); i++ {
fmt.Scan(&arr[i])
}
positive := 0
negative := 0
zero_ := 0
for _, arr_v := range arr {
if arr_v > 0 {
positive++
} else if arr_v < 0 {
negative++
} else if arr_v == 0 {
zero_++
}
}
fmt.Printf("%f ", float32(positive/len(arr)))
fmt.Printf("%f ", float32(negative/len(arr)))
fmt.Printf("%f ", float32(zero_/len(arr)))
}
i mean to output
A decimal representing of the fraction of positive numbers in the array. A decimal representing of the fraction of negative numbers in the array. A decimal representing of the fraction of zeroes in the array.
Sample Input
6
-4 3 -9 0 4 1
Sample Output
0.500000
0.333333
0.166667
but in my code the output like this with the same input
0.000000
0.000000
0.000000