解题思路:
在主函数中定义c,f保存摄氏温度和华氏温度,然后根据题意用for循环依次获取-100~150之间的温度,将获取的温度传入到自定义函数ctof中,在自定义函数ctof中使用公式f=32+c*9/5计算出每个摄氏温度对应的华氏温度,然后返回到主函数中赋值给变量f,然后根据题目格式将结果输出。
参考代码:
#include<iostream> using namespace std; int ctof(int c) { int f; f = 32+c*9/5; return f; } int main() { int c; int f; for(c=-100;c<=150;c+=5) { f=ctof(c); cout<<"c="<<c<<"->"<<"f="<<f<<endl; } return 0; }
0.0分
20 人评分