题目:
已知华氏温度到摄氏温度的转换公式为
C=5/9(F-32)
试编写一个将华氏温度转换到摄氏温度的函数。
代码:
#include <iostream>
using namespace std;
double function(double f);
int main()
{
double f;
cout << "将华氏温度转换为摄氏温度" << endl << endl;
cout << "请输入华氏温度:";
cin >> f;
cout << "对应的摄氏温度为:" << function(f) << endl << endl;
system("pause");
return 0;
}
double function(double f)
{
return (f - 32) * 5 / 9;
}