Get the App
SLTechnology News&Howtos  ›  Development  › 

If worsening, use command line parameters to find the mean.

Shulou Source: shulou.com Published: 2022-06-03 06:21:38 10月03日 Update

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!

Tags: Parameters commands mean learning content that is ideas situations articles more knowledge knowledge points articles follow questions practice push research verification Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Microsoft Docker macOS Huawei