酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

输入一个华氏温度,要求输出摄氏温度(小数点保留2位)。公式为c=5/9(f-32)。 样例: 输入: 100 输出: 37.78

以下是使用 Python 语言实现的代码: ```python f = float(input("请输入华氏温度:")) c = 5 / 9 * (f - 32) print("%.2f" % c) ``` 如果您使用的是其他编程语言,例如 C++: ```cpp #include <iostream> using namespace std; int main() { double f; cout << "请输入华氏温度:"; cin >> f; double c = 5.0 / 9 * (f - 32); printf("%.2f\n", c); return 0; } ``` 如果是 Java 语言: ```java import java.util.Scanner; public class TemperatureConversion { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("请输入华氏温度:"); double f = scanner.nextDouble(); double c = 5.0 / 9 * (f - 32); System.out.printf("%.2f", c); scanner.close(); } } ``` [2024-09-30 00:19:15 | AI写代码神器 | 259点数解答]

相关提问