Я могу предоставить вам несколько методов преобразования температуры вместе с примерами кода. Вот некоторые популярные языки программирования и соответствующие им фрагменты кода:
-
Python:
def celsius_to_fahrenheit(celsius): return (celsius * 9/5) + 32 def fahrenheit_to_celsius(fahrenheit): return (fahrenheit - 32) * 5/9 -
JavaScript:
function celsiusToFahrenheit(celsius) { return (celsius * 9/5) + 32; } function fahrenheitToCelsius(fahrenheit) { return (fahrenheit - 32) * 5/9; } -
Java:
public class TemperatureConverter { public static double celsiusToFahrenheit(double celsius) { return (celsius * 9/5) + 32; } public static double fahrenheitToCelsius(double fahrenheit) { return (fahrenheit - 32) * 5/9; } } -
C++:
#include <iostream> double celsiusToFahrenheit(double celsius) { return (celsius * 9/5) + 32; } double fahrenheitToCelsius(double fahrenheit) { return (fahrenheit - 32) * 5/9; } int main() { double celsius = 25.0; std::cout << "Celsius to Fahrenheit: " << celsiusToFahrenheit(celsius) << std::endl; double fahrenheit = 77.0; std::cout << "Fahrenheit to Celsius: " << fahrenheitToCelsius(fahrenheit) << std::endl; return 0; }
Эти примеры описывают преобразование шкал Цельсия и Фаренгейта. Вы можете ввести значение температуры, которое хотите преобразовать, в соответствующую функцию преобразования.