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

โปรแกรม C# แปลงอุณหภูมิ เซลเซียสเป็นฟาเรนไฮต์

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

double celsius = 36;
double fahrenheit = (celsius * 9) / 5 + 32;

ตัวอย่างโค้ดเต็ม

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo {
    class MyApplication {
        static void Main(string[] args) {
            double fahrenheit;
            double celsius = 36;
            Console.WriteLine("Celsius: " + celsius);
            fahrenheit = (celsius * 9) / 5 + 32;
            Console.WriteLine("Fahrenheit: " + fahrenheit);
            Console.ReadLine();
        }
    }
}

ผลลัพธ์

Celsius: 36
Fahrenheit: 96.8

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