@ -15,4 +15,4 @@
|11|new|new函数案例一|
|12|gcd|最大公约数|
|13|type|类型别名|
|14|||
|14|tempconv&kelvins|开尔文温度转换|
@ -0,0 +1,13 @@
package main
import (
"fmt"
"tempconv"
)
func main() {
fmt.Println("Kelvins~")
fmt.Printf("Kelvins AbsoluteZero: %v~\n", tempconv.AbsoluteZeroK)
fmt.Println(tempconv.KtoC(tempconv.AbsoluteZeroK))
fmt.Printf("%g\n", tempconv.KtoC(tempconv.AbsoluteZeroK))
}
@ -0,0 +1,8 @@
package tempconv
func KtoC(k Kelvins) Celsius {
return Celsius(k - 273.15)
func CtoK(c Celsius) Kelvins {
return Kelvins(c + 273.15)
@ -0,0 +1,15 @@
import "fmt"
type Kelvins float64
type Celsius float64
const (
AbsoluteZeroK Kelvins = 0
FreezingK Kelvins = 273.15
boilingK Kelvins = 373.15
func (c Celsius) String() string { return fmt.Sprintf("%g°C", c) }
func (k Kelvins) String() string { return fmt.Sprintf("%g°C", k) }