用c语言编写程序计算并输出华氏温度80F所对应的摄氏温度C。转换公式为:C=5/9×(F-32),并利用float型数据进行运算。
时间: 2024-05-19 13:15:36 浏览: 11
答案:
华氏温度80F所对应的摄氏温度C为26.666666。以下是用C语言编写的程序:
#include <stdio.h>
int main()
{
float fahrenheit = 80;
float celsius = 5.0 / 9 * (fahrenheit - 32);
printf("%.2fF = %.2fC", fahrenheit, celsius);
return 0;
}
输出结果为:
80.00F = 26.67C
相关问题
用c语言编写程序,计算并输出华氏温度为80F所对应的摄氏温度C。 转换公式为:C=5* (F-32) /9
```c
#include <stdio.h>
int main() {
float fahrenheit = 80; // 摄氏温度
float celsius; // 华氏温度
celsius = 5 * (fahrenheit - 32) / 9;
printf("华氏温度为 %.2f°F,对应的摄氏温度为 %.2f°C", fahrenheit, celsius);
return 0;
}
```
用C++帮我编写一个程序: 计算并输出华氏温度80F所对应的摄氏温度C。转换公式为:C=5/9×(F-32),并利用float型数据进行运算。
好的,以下是程序代码:
``` c
#include <stdio.h>
int main() {
float f = 80.0; // 华氏温度80F
float c = 5.0 / 9.0 * (f - 32.0); // 转换为摄氏温度
printf("华氏温度80F对应的摄氏温度为%.2fC\n", c); // 输出结果,保留两位小数
return 0;
}
```
希望能对您有所帮助!