mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2025-08-10 00:51:52 +00:00
good good study, day day up!
This commit is contained in:
22
vendor/gopl.io/ch2/ftoc/main.go
generated
vendored
Normal file
22
vendor/gopl.io/ch2/ftoc/main.go
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
|
||||
// See page 29.
|
||||
//!+
|
||||
|
||||
// Ftoc prints two Fahrenheit-to-Celsius conversions.
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
const freezingF, boilingF = 32.0, 212.0
|
||||
fmt.Printf("%g°F = %g°C\n", freezingF, fToC(freezingF)) // "32°F = 0°C"
|
||||
fmt.Printf("%g°F = %g°C\n", boilingF, fToC(boilingF)) // "212°F = 100°C"
|
||||
}
|
||||
|
||||
func fToC(f float64) float64 {
|
||||
return (f - 32) * 5 / 9
|
||||
}
|
||||
|
||||
//!-
|
Reference in New Issue
Block a user