2 Star 6 Fork 3

Cyouagain / C语言经典编程详解

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
【C语言经典编程】练习2-12 输出华氏-摄氏温度转换表 (15分).md 1.57 KB
一键复制 编辑 原始数据 按行查看 历史

微信搜索公众号【IT学长】:

练习2-12 输出华氏-摄氏温度转换表

输入2个正整数lower和upper(lower≤upper≤100),请输出一张取值范围为[lower,upper]、且每次增加2华氏度的华氏-摄氏温度转换表。

温度转换的计算公式:C=5×(F−32)/9,其中:C表示摄氏温度,F表示华氏温度。

输入格式:

在一行中输入2个整数,分别表示lower和upper的值,中间用空格分开。

输出格式:

第一行输出:"fahr celsius"

接着每行输出一个华氏温度fahr(整型)与一个摄氏温度celsius(占据6个字符宽度,靠右对齐,保留1位小数)。

若输入的范围不合法,则输出"Invalid."。

输入样例1:

32 35

输出样例1:

fahr celsius 32 0.0 34 1.1

输入样例2:

40 30

输出样例2:

Invalid.

代码:

#include<stdio.h>
int main()
{
  int lower,upper;
  int i;
  scanf("%d %d",&lower,&upper);
  if(lower<=upper)
    {
      printf("fahr celsius\n");
      for(i=lower;i<=upper;i+=2)
      {
        printf("%d%6.1lf\n",i,(double)(5.0*(i-32)/9.0));
      }

    }
    else printf("Invalid.\n");
  return 0;
}
C
1
https://gitee.com/cyouagain/C_pta.git
git@gitee.com:cyouagain/C_pta.git
cyouagain
C_pta
C语言经典编程详解
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891