温度转换 C++实现
#include <iostream>
using namespace std;
int main(void)
{
double f;
cin >> f;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(3);
cout << (f - 32) * 5 / 9 << endl;
return 0;
} 只要确保表达式的第一个数是浮点数,表达式后面的数都会默认转换为浮点数在进行运算。
所以我们只要稍微调整下式子的运算顺序使得浮点数在第一个就可以。
