温度(temperature)转换--算法竞赛入门习题1-2:输入华氏温度f,输出对应的摄氏温度c,保留三位小数。提示:c=5(f-32)/9

温度(temperature)转换–算法竞赛入门习题1-2:输入华氏温度f,输出对应的摄氏温度c,保留三位小数。提示:c=5(f-32)/9(C++实现)

#include<stdio.h>
#include <iostream>
using namespace std;
int main()
{
	double f;
	cout << "请输入华氏温度" << endl;
	cin >> f ;
	double c = 5*(f-32) / 9;
	cout.setf(ios::showpoint); //将小数精度后面的0显示出来
	cout.precision(3);
	cout <<"对应的摄氏温度为:" << c << endl;
	return 0;
}

实例运行图:
请添加图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: \u8fd9\u91cc\u662f\u4e00\u4e2a\u7b80\u5355\u7684C\u8bed\u8a00\u7a0b\u5e8f\uff0c\u7528\u4e8e\u8f93\u5165\u4e00\u4e2a\u534e\u6c0f\u6e29\u5ea6\uff0c\u5e76\u8ba9\u7a0b\u5e8f\u8fdb\u884c\u8ba1\u7b97\u5e76\u8f93\u51fa\u7ed3\u679c\u3002 \u4ee5\u4e0b\u662f\u7b80\u5355\u7684C\u4ee3\u7801\uff1a ```c #include <stdio.h> int main() { float f, c; printf("Please enter the temperature in Fahrenheit: "); scanf("%f", &f); c = 5.0 * (f - 32.0) / 9.0; printf("%.2f Fahrenheit = %.2f Celsius", f, c); return 0; } ``` \u4f7f\u7528\u8fd9\u4e2a\u7a0b\u5e8f\uff0c\u4f60\u53ef\u4ee5\u8f93\u5165\u4e00\u4e2a\u534e\u6c0f\u6e29\u5ea6\uff0c\u7a0b\u5e8f\u5c06\u8ba1\u7b97\u5b8c\u6210\u540e\uff0c\u8f93\u51fa\u7ed3\u679c\u4f7f\u7528\u53cc\u7cbe\u5ea6\u663e\u793a\uff0c\u5e76\u53d6\u5f97\u5b57\u7b26\u4e32\u4e2d\u7684\u4e24\u4f4d\u5c0f\u6570\u3002 \u4f8b\u5982\uff0c\u5982\u679c\u8f93\u5165\u7684\u534e\u6c0f\u6e29\u5ea6\u662f 98.6\u00b0F\uff0c\u5219\u7a0b\u5e8f\u5c06\u8f93\u51fa\u5982\u4e0b\u7ed3\u679c\uff1a ``` Please enter the temperature in Fahrenheit: 98.6 98.60 Fahrenheit = 37.00 Celsius ``` \u56e0\u4e3a\u4e24\u4f4d\u5c0f\u6570\u662f00\uff0c\u6240\u4ee5\u53d6\u4e24\u4f4d\u5c0f\u6570\u540d\u4e3a37\u3002 ### 回答2: 如下所示为一个编写的C语言程序,用于将输入华氏温度转换摄氏温度,并将结果保留两位小数: ```c #include <stdio.h> int main() { float fahrenheit, celsius; // 读取输入华氏温度 printf("请输入华氏温度:"); scanf("%f", &fahrenheit); // 根据转换公式计算摄氏温度 celsius = 5 * (fahrenheit - 32) / 9; // 输出结果保留两位小数 printf("摄氏温度为:%.2f\n", celsius); return 0; } ``` 使用此程序,您可以输入一个华氏温度,并计算其对应摄氏温度。程序将输出结果保留两位小数点,以方便阅读。 ### 回答3: 编写C语言程序,实现华氏温度摄氏温度的功能。代码如下: ```c #include <stdio.h> int main() { float fahrenheit, celsius; // 输入华氏温度 printf("请输入华氏温度:"); scanf("%f", &fahrenheit); // 进行温度转换 celsius = 5 * (fahrenheit - 32) / 9; // 输出结果 printf("摄氏温度为:%.2f\n", celsius); return 0; } ``` 首先,我们定义两个浮点型变量fahrenheit和celsius,用于存储输入华氏温度和计算得到的摄氏温度。 然后,通过使用printf函数提示用户输入华氏温度,并使用scanf函数读取用户输入的值,将其保存在fahrenheit变量中。 接下来,根据公式c=5×(f-32)÷9进行温度转换,将计算结果保存在celsius变量中。 最后,通过使用printf函数将摄氏温度的值输出到屏幕上,保留两位小数。 用户可以根据程序的提示输入任意的华氏温度,并获得相应的摄氏温度结果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值