- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 6969 个
- 通用积分
- 13.9949
- 学术水平
- 11 点
- 热心指数
- 15 点
- 信用等级
- 4 点
- 经验
- 4658 点
- 帖子
- 204
- 精华
- 0
- 在线时间
- 357 小时
- 注册时间
- 2014-11-4
- 最后登录
- 2024-12-13
|
练习1.5
- #include <stdio.h>
- float C2F(float C){
- float F;
- F = 9.0 * C / 5.0 + 32.0;
- return F;
- }
- float F2C(float F){
- float C;
- C = (F - 32.0) * 5.0 / 9.0;
- return C;
- }
- main(){
- /*
- 摄氏温度与华氏温度的相互转换
-
- Args:
- Cel:摄氏温度;
- Fah:华氏温度 .
- */
- printf("Input F/C for program to converse: ");
- char i;
- scanf("%c", &i);
-
- if(i == 'C'){
- float Cel;
- scanf("%f", &Cel);
- printf("The Celsius temperature you input is: %.3f\n", Cel);
- printf("The corresponding Fahrenheit temperature is: %.3f\n", C2F(Cel));
- }
- else{
- float Fah;
- scanf("%f", &Fah);
- printf("The Fahrenheit temperature you input is: %.3f\n", Fah);
- printf("The corresponding Celsius temperature is: %.3f\n", F2C(Fah));
- }
- }
复制代码
|
|