当前位置:网站首页>C language brush question | temperature conversion (11)
C language brush question | temperature conversion (11)
2022-06-22 09:14:00 【C language train】
example 11: Someone used a thermometer to measure the temperature in Fahrenheit 98°F, Now ask for C The language implementation converts it to the temperature expressed in Celsius .
Their thinking : The algorithm for this problem is very simple , The key is to find the conversion formula between the two , Celsius equals five ninths times Fahrenheit minus 32 Product of , That is to say :
centigrade=(5.0/9)*(f_Degree-32);Source code demo :
#include<stdio.h>// The header file
int main() // The main function
{
float f_Degree,centigrade; // Define floating point variables
f_Degree=98.0;// Initialize the Fahrenheit variable
centigrade=(5.0/9)*(f_Degree-32);// Note that this should be 5.0
printf(" Fahrenheit 98 The degree Celsius of is :%f\n",centigrade);// Output results
return 0;// The return value of the function is 0
}Compilation result :
Fahrenheit 98 The degree Celsius of is :36.666668
--------------------------------
Process exited after 1.796 seconds with return value 0
Please press any key to continue . . .The reader should be able to easily understand this example , But there is one thing that requires the reader's special attention , This is the line of code
centigrade=(5.0/9)*(f_Degree-32);If written
centigrade=(5/9)*(f_Degree-32);Then there will be logical errors , The following output :
Fahrenheit 98 The degree Celsius of is :0.000000
--------------------------------
Process exited after 1.967 seconds with return value 0
Please press any key to continue . . .Why ?
stay C No format is declared in the language , The divisor of this integer is larger than the divisor , Will be directly equal to 0, There is no number after the decimal point .
边栏推荐
- Unicode字符/静态非静态的访问
- Two threads execute i++ 100 times respectively, and the possible values obtained
- 函数总结(1)
- How much do you know about the required encryption industry terms in 2022?
- Express bird of Express query demonstration code (php+curl)
- C语言刷题 | 温度转换(11)
- User insight into the video industry in January 2022: active users began to pick up under the influence of holidays
- 滴滴二面总结
- list_ head
- 经典&&案例
猜你喜欢

File upload attack and protection

Fanatical NFT, foam or tuyere?

Solidity from introduction to practice (IV)

【node】node+短信api 实现验证码登录

Kali Trojan invades win7 system

项目优化+上线(掌握了么?)

希望越来越多的女性从事科技工作
![[network security officer] an attack technology that needs to be understood - high hidden and high persistent threats](/img/c9/c0ee95e816cac698f5397cc369d9ec.jpg)
[network security officer] an attack technology that needs to be understood - high hidden and high persistent threats

Performance optimization topics
![[tensorboard] step on all minefields and solve all your problems](/img/35/fc0f7ed311bf7c0321e1257ff6a1a6.png)
[tensorboard] step on all minefields and solve all your problems
随机推荐
Performance optimization topics
Manually mining XSS vulnerabilities
逻辑回归和线性回归
rewrite? Reload? Are you dizzy?
模糊查询和聚合函数
进程状态汇总
断言assert()
PHP de duplication and arrange complete small functions in descending order of length
Development error reporting record
Fanatical NFT, foam or tuyere?
DOM编程
機器學習|nltk_Data下載錯誤|nltk的stopwords語料下載錯誤解决方法
Kali Trojan invades win7 system
copy_from_user和copy_to_user
5 interview questions, grasp the underlying principle of string!
Machine learning | nltk_ Data download error |nltk's stopwords corpus download error solution
函数总结(1)
Local visualization method of xshell remote server tensorboard/visdom [one-step test is effective]
C语言刷题 | 判断某年是否只闰年(12)
【node】脚手架搭建服务器,完成token验证