【C++ Primer Plus习题】2.5
问题:
解答:
#include <iostream>
using namespace std;#define CEL_TO_FAH(c) 1.8*c+32.0float celToFah(float value)
{float fahrenheit = CEL_TO_FAH(value);return fahrenheit;
}int main()
{float celsius = 0;cout << "请输入一个摄氏温度的值:";cin >> celsius;float res = celToFah(celsius);cout << celsius << "摄氏温度 = " << res << "化氏温度" << endl;return 0;
}
运行结果:

考查点:
- 函数的传值和返回值
注意:
宏函数,参数会直接替代在原式中的变量.



