Problem Statement: Write a C# program that converts a temperature in Fahrenheit to Celsius. Take the temperature in Fahrenheit as user input and display the converted temperature in Celsius.
Example:
Input: Fahrenheit: 98.6 Output: 98.6°F is equal to 37°C
The formula to convert temperature from Fahrenheit (°F) to Celsius (°C) is as follows:
Celsius (°C) = (Fahrenheit (°F) - 32) × 5/9
C# Code to Convert Fahrenheit to Celsius.
// C-sharp code to calculate celsius using System; namespace TemperatureConverter { class Program { static void Main(string[] args) { // Read temperature in Fahrenheit from the user Console.Write("Enter the temperature in Fahrenheit: "); double fahrenheit = Convert.ToDouble(Console.ReadLine()); // Convert Fahrenheit to Celsius using the formula double celsius = (fahrenheit - 32) * 5 / 9; // Display the converted temperature Console.WriteLine($"{fahrenheit} F is equal to {celsius:F2} C"); // Keep the console window open Console.ReadLine(); } } }
Enter the temperature in Fahrenheit: 45
45 F is equal to 7.22 C
No comments:
Post a Comment