Go語言程式:攝氏溫度轉換為華氏溫度


步驟

  • 獲取攝氏溫度值並將其儲存在一個變數中。
  • 將其轉換為華氏溫度。
  • 列印最終結果。
輸入攝氏溫度: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

更新於: 2021年7月31日

428 次瀏覽

開啟你的職業生涯

透過完成課程獲得認證

立即開始
廣告

© . All rights reserved.