从键盘上输入一个摄氏温度c,求该温度所对应的华氏温度f(f=c*5/9+32)
/*输入一个华氏温度f,计算并输出对应的摄氏温度。计算摄氏温度的公式为:c=5/9*(f-32),输出取两位小数。*/
#include <stdio.h>
#include <conio.h>
int main (void)
{
double f,c;
printf ("请输入一个华氏温度:\n");
scanf ("%lf",&f);
c=5*(f-32)/9; //这里稍作处理,因为5/9=0
printf ("对应的摄氏温度为%.2lf\n",c);
getch();
}
#include <stdio.h>
int main()
{
float n;
char d;
scanf("%f",&n);
scanf("%c",&d);
if (d=='f' || d=='F')
{
float c=5*(n-32)/9;
printf("摄氏温度:%.2f",c);
}
else if (d=='c' || d=='C')
{
float f=n*9/5+32;
printf("华氏温度%.2f",f);
}
else
printf("Error!");
return 0;
}