2023-11-10 12:53:12 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
func averageCalc(numbers ...float64) float64 {
|
|
|
|
var sum float64 = 0
|
|
|
|
for _, number := range numbers {
|
|
|
|
sum += number
|
|
|
|
}
|
|
|
|
return sum / float64(len(numbers))
|
|
|
|
}
|
|
|
|
|
2024-02-03 11:15:06 -05:00
|
|
|
func main() {
|
2023-11-10 12:53:12 -05:00
|
|
|
arguments := os.Args[1:]
|
|
|
|
var numbers []float64
|
|
|
|
for _, argument := range arguments {
|
|
|
|
number, err := strconv.ParseFloat(argument, 64)
|
|
|
|
Error(err)
|
|
|
|
numbers = append(numbers, number)
|
|
|
|
}
|
2024-02-03 11:15:06 -05:00
|
|
|
fmt.Printf("Average: %0.2f\n", averageCalc(numbers...))
|
2023-11-10 12:53:12 -05:00
|
|
|
}
|