1700 - 2005年春浙江省计算机等级考试二级C 编程题(2)
输出一张摄氏一华氏温度转换表,摄氏温度的取值区间是[-1000 C,1500C ],温度间隔50C。要求定义和调用函数 ctof(c),将摄氏温度C转换成华氏温度F,计算公式:
F = 32 + C* 9/5。
例如
c=0->f=32
c=5->f=41
c=10->f=50
c=15->f=59
c=20->f=68
c=25->f=77
c=30->f=86
c=35->f=95
c=40->f=104
c=45->f=113
c=50->f=122
c=55->f=131
c=60->f=140
c=65->f=149
题目输入
题目输出
输入/输出样例
题目输入
题目输出
C语言解答
#include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int ctof(int c) { int f; f=32+c*9/5; return f; } int main(int argc, char *argv[]) { int c,f; for(c=-100;c<=150;c+=5) { f=ctof(c); printf("c=%d->f=%d\n",c,f); } return 0; }
C++解答
#include<iostream> using namespace std; int ctof(int c) { return 32+c*9/5; } int main() { for (int c=-100; c<=150; c+=5) cout<<"c="<<c<<"->f="<<ctof(c)<<endl; return 0; }