嗨,我是Go编程语言的新手。
我正在从http://www.golang-book.com/学习
在第4章的练习中,有一个关于从华氏温度转换为摄氏度的问题。
我将答案编码如下
package main
import "fmt"
func main(){
fmt.Println("Enter temperature in Farentheit ");
var input float64
fmt.Scanf("%f",&input)
var outpu1 float64 = ( ( (input-32)* (5) ) /9)
var outpu2 float64= (input-32) * (5/9)
var outpu3 float64= (input -32) * 5/9
var outpu4 float64= ( (input-32) * (5/9) )
fmt.Println("the temperature in Centigrade is ",outpu1)
fmt.Println("the temperature in Centigrade is ",outpu2)
fmt.Println("the temperature in Centigrade is ",outpu3)
fmt.Println("the temperature in Centigrade is ",outpu4)
}
输出如下
sreeprasad:projectsInGo sreeprasad$ go run convertFarentheitToCentigrade.go
Enter temperature in Farentheit
12.234234
the temperature in Centigrade is -10.980981111111111
the temperature in Centigrade is -0
the temperature in Centigrade is -10.980981111111111
the temperature in Centigrade is -0
我的问题是关于outpu2和outpu4。括号是正确的,但是它如何或为什么显示-0。
谁能解释一下
开满天机
天涯尽头无女友
桃花长相依
随时随地看视频慕课网APP
相关分类