If worsening, use command line parameters to find the mean.
This article mainly explains "such as worsening the use of command-line parameters to find the mean". The explanation in the article is simple and clear, and is easy to learn and understand. let's study and learn "such as worsening the use of command-line parameters to find the average"!
Package mainimport ("fmt"log"os"strconv") func average (numbers... float64) float64 {var sum float64 = 0 for _, number: = range numbers {sum + = number} return sum / float64 (len (numbers))} func main () {arguments: = os.Args [1:] var numbers [] float64 for _ Argument: = range arguments {number, err: = strconv.ParseFloat (argument, 64) if err! = nil {log.Fatal (err)} numbers = append (numbers, number)} fmt.Printf ("Average value is% 0.2f", average (numbers...))}
[root@VM-centos ~ / average] #. / main 100 200 300
Average value is 200.00
Thank you for your reading, the above is the content of "if worsening the use of command-line parameters to find the mean". After the study of this article, I believe you have a deeper understanding of the problem of using command-line parameters to find the mean. The specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!