《go語言聖經》練習題

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。為了督促並記錄自己關於GO語言的學習,從現在開始會記錄下我學習GO語言的曆程。下面呢是習題2.1和2.2的練習題:2.1、tempconv包下的tempconv.go:```gopackage tempconvtype K float32type C float32func KToC(k K) C {return C(-273.15 + k)}func CToK(c C) K {return K(c + 273.15)}```在practice_0201檔案下的main.go裡引入tempconv包並調用輸出:```gopackage mainimport ("fmt""tempconv")func main() {//fmt.Println("Hello World!")var k tempconv.K = 1c := tempconv.KToC(k)fmt.Println(c)var c0 tempconv.C = 1k0 := tempconv.CToK(c0)fmt.Println(k0)}```2.2、```go// practice_0202 project main.gopackage mainimport ("fmt")type Transf struct {Celsius float32Fahrenheit float32Inch float32M float32Pound float32KG float32}func main() {transform(20)}func transform(n float32) {var trans Transftrans.Celsius = -273.15 + ntrans.Fahrenheit = n + 273.15trans.Inch = n * 0.0254trans.M = n / 0.0254trans.Pound = 0.4535924 * ntrans.KG = n / 0.4535924fmt.Println(n, "Fahrenheit=", trans.Celsius, "Celsius")fmt.Println(n, "Celsius=", trans.Fahrenheit, "Fahrenheit")fmt.Println(n, "Inch=", trans.M, "M")fmt.Println(n, "M=", trans.Inch, "Inch")fmt.Println(n, "Pound=", trans.KG, "KG")fmt.Println(n, "KG=", trans.Pound, "Pound")}```837 次點擊  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.