C# 程式轉換為華氏溫度到攝氏溫度
首先,設定華氏溫度 −
double fahrenheit = 97; Console.WriteLine("Fahrenheit: " + fahrenheit);
現在轉換為攝氏溫度 −
celsius = (fahrenheit - 32) * 5 / 9;
示例
你可以嘗試執行以下程式碼,將華氏溫度轉換為攝氏溫度。
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo { class MyApplication { static void Main(string[] args) { double celsius; double fahrenheit = 97; Console.WriteLine("Fahrenheit: " + fahrenheit); celsius = (fahrenheit - 32) * 5 / 9; Console.WriteLine("Celsius: " + celsius); Console.ReadLine(); } } }
輸出
Fahrenheit: 97 Celsius: 36.1111111111111
廣告