mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2024-12-01 10:38:59 +00:00
23 lines
509 B
Go
23 lines
509 B
Go
|
// 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
|
||
|
}
|
||
|
|
||
|
//!-
|