From 5dfebeee549246302cabba05d254ca5c632b7a92 Mon Sep 17 00:00:00 2001 From: Igor V Belousov Date: Mon, 10 Jan 2022 20:04:08 +0000 Subject: [PATCH] add tempconv0 ch2 --- ch2/tempconv0.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 ch2/tempconv0.go diff --git a/ch2/tempconv0.go b/ch2/tempconv0.go new file mode 100644 index 0000000..79e62d0 --- /dev/null +++ b/ch2/tempconv0.go @@ -0,0 +1,25 @@ +// Пакет tempconv выполняет вычисления температур +// по Цельсию (Celsius) и по Фаренгейту (Fahrenheit). +package main + +import ( + "fmt" +) + +type Celsius float64 +type Fahrenheit float64 + +const ( + AbsoluteZeroC Celsius = -273.15 + FreezingC Celsius = 0 + BoilingC Celsius = 100 +) + +func CToF(c Celsius) Fahrenheit { return Fahrenheit(c*9/5 + 32) } +func FToC(f Fahrenheit) Celsius { return Celsius((f - 32) * 5 / 9) } + +func main() { + fmt.Printf("%g\n", BoilingC) + boilingF := CToF(BoilingC) + fmt.Printf("g%\n", boilingF) +}