Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

โปรแกรม C# แปลงฟาเรนไฮต์เป็นเซลเซียส

สูตรการแปลง: Celsius = (Fahrenheit - 32) × 5/9

double fahrenheit = 97;
double 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

สูตรกลับกัน: Fahrenheit = (Celsius * 9) / 5 + 32