在C语言中输入华氏温度输出摄氏温度
时间: 2024-05-09 15:18:47 浏览: 82
可以使用以下公式将华氏温度转换为摄氏温度:
C = (F - 32) * 5 / 9
其中C表示摄氏温度,F表示华氏温度。
以下是一个示例程序:
```c
#include <stdio.h>
int main()
{
float fahrenheit, celsius;
printf("请输入华氏温度:");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) * 5 / 9;
printf("摄氏温度为:%.2f\n", celsius);
return 0;
}
```
运行程序后,输入一个华氏温度,程序将输出对应的摄氏温度。注意,程序中使用了浮点数类型(float)来存储温度值,以保留小数点后面的精度。
相关问题
c语言输入华氏温度输出摄氏温度
可以使用以下公式进行转换:
Celsius = (Fahrenheit - 32) * 5 / 9
其中,Celsius 表示摄氏温度,Fahrenheit 表示华氏温度。因此,可以编写以下 C 语言代码实现该功能:
#include <stdio.h>
int main() {
float fahrenheit, celsius;
printf("请输入华氏温度:");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) * 5 / 9;
printf("摄氏温度为:%.2f\n", celsius);
return 0;
}
C语言键盘输入华氏温度,输出摄氏温度
在C语言中,可以使用以下公式将华氏温度转换为摄氏温度:
```
C = (F - 32) * 5 / 9
```
其中,C为摄氏温度,F为华氏温度。下面是一个示例代码:
```c
#include <stdio.h>
int main() {
float fahrenheit, celsius;
printf("请输入华氏温度:");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) * 5 / 9;
printf("摄氏温度为:%.2f\n", celsius);
return 0;
}
```
在这个例子中,我们从键盘输入华氏温度,将其转换为摄氏温度,并输出结果。需要注意的是,我们使用了`%f`格式化字符来读取浮点数。
阅读全文
相关推荐
















