题目内容:
编程:实现华氏温度和摄氏温度的相互转换。例如,当输入一个华氏温度,输出对应的摄氏温度;当输入一个摄氏温度,输出对应的华氏温度。
设华氏温度为f,摄氏温度为c,则:
输入格式:
%lf%c
输出格式:
%.1lf%c
输入样例1(F表示华氏温度):
50F
输出样例1(C表示摄氏温度):
10.0C
输入样例2(C表示摄氏温度):
10C
输出样例2(F表示华氏温度):
50.0F
输入样例3(如果表示温度类型的字母不是F或C时,则提示错误):
10D
输出样例3:
error
时间限制:500ms内存限制:32000kb
#include <stdio.h>
int main()
{
double temp;
char type;
scanf("%lf%c", &temp, &type);
if (type == 'F')
{
temp = 5 * (temp - 32) / 9;
type = 'C';
}
else if (type == 'C')
{
temp = 9 * temp / 5 + 32;
type = 'F';
}
else
{
printf("error\n");
return 0;
}
printf("%.1lf%c\n", temp, type);
return 0;
}