Golang程序 获取摄氏温度并转换为华氏温度
步骤
- 取摄氏温度值并将其存储在一个变量中。
- 将其转换为华氏温度。
- 打印最终结果。
输入摄氏度的温度。32
华氏的温度是。89.6
输入摄氏度的温度。48
华氏的温度是。118.4
说明
- 用户必须首先输入摄氏温度的数值。
- 使用公式:
f=(c*1.8)+32
,将摄氏温度转换为华氏温度。 - 打印华氏温度。
例子
package main
import "fmt"
func main(){
var n int
fmt.Print("Enter the temperature in Celsius:")
fmt.Scanf("%d", &n)
f:=(float32(n)*1.8)+32
fmt.Println("Temperature in Fahrenheit is:", f)
}
输出
Enter the temperature in Celsius:32
Temperature in Fahrenheit is: 89.6