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
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP