Đầu tiên, đặt nhiệt độ độ F -
double fahrenheit = 97;
Console.WriteLine("Fahrenheit: " + fahrenheit); Bây giờ chuyển nó thành độ C -
celsius = (fahrenheit - 32) * 5 / 9;
Ví dụ
Bạn có thể thử chạy mã sau để chuyển đổi độ F sang độ C.
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();
}
}
} Đầu ra
Fahrenheit: 97 Celsius: 36.1111111111111