A program to print Fahrenheit-Celsius table with floating-point values
Another
program to print Fahrenheit-Celsius table with decimal integer
This program is presented
as below.
#include <stdio.h>
/* print Fahrenheit_Celsius table
for fahr = 0, 20, ..., 300; floating-point version */
int main()
{
float fahr, celsius;
int lower, upper, step; lower = 0; /* lower limit of temperature table */
upper = 300; /* upper limit of temperature table */
step = 20; /* step size */ fahr = lower;
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%3.0f %6.1f\n", fahr, celsius);
fahr = fahr + step;
} return 0;
}
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYWJuZXJ3YW5nMjAxNA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
The figure of this program is presented as above. The right part of the figure is the output. This is much like the program which is mentioned at the beginning of the article, except that fahr and celsius are
declared to be float. We were unable to use 5/9 in the previous version because integer division would truncate it to zero. A
decimal point in a constant indicates that it is floating point, however, so 5.0/9.0 is not truncated because it is the ratio of two floating-point values.
If an arithmetic operator has integer operands, an integer operation is performed. If
an arithmetic operator has one floating-point operand and one integer operand, however, the integer will be converted to floating point before the operation is done. Writing floating-point constants with explicit decimal points even when
they have integral values emphasizes their floating-point nature for human readers.
For now, notice that the assignment
fahr = lower;
and the test
while (fahr <= upper)
also work in the nature way — the int is converted to float before the operation is done.
The implications of width and precision are tabled as follows.
- %d print as decimal integer
- %6d print as decimal integer, at least 6 characters wide
- %f print as foating point
- %6f print as floating point, at least 6 characters wide
- %.2f print as floating point, 2 characters after decimal point
- %6.2f print as floating point, at leat 6 wide and 2 characters after decimal point
Among others, printf also recognizes %o for
octal, %x for hexadecimal, %c for
character, %s for charater string, and %% for % itself.
Reference
A program to print Fahrenheit-Celsius table with floating-point values的更多相关文章
- @media print样式 关于table断页
<html> <head> <style> @media print { table { page-break-after:auto } tr { page-bre ...
- python3变量和数据类型
变量和数据类型 知识点 python 关键字 变量的定义与赋值 input() 函数 字符串的格式化 实验步骤 每一种编程语言都有它们自己的语法规则,就像我们所说的外语. 1. 关键字和标识符 ...
- Python3简明教程(二)—— 变量和数据类型
关键字和标识符 下列的标识符是Python3的关键字,并且不能用于通常的标识符.关键字必须严格按照下面的拼写: False def if raise None del import return Tr ...
- ABAP program lines are wider than the internal table
错误详细描述: An exception occurred that is explained in detail below.The exception, which is assigned to ...
- Why is celsius = 5 * (fahr - 32) / 9 ?
Go to my personal blog There is a program to print Fahrenheit-Celsius table as below. #include <s ...
- Codeforces Round #344 (Div. 2) B. Print Check
B. Print Check time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Python multi-thread 多线程 print 如何避免print的结果混乱
multithread如何写 这是我第一次写multithread,所以就是照着例子学,下面是我用来学的例子 来自于”Automate the boring stuff with Python”的15 ...
- Calling Lua From a C Program
Introduction From a running C program, you can call a Lua script. The C program can pass arguments t ...
- Codeforces Round #344 (Div. 2) B. Print Check 水题
B. Print Check 题目连接: http://www.codeforces.com/contest/631/problem/B Description Kris works in a lar ...
随机推荐
- js 上传图片、压缩、旋转
亲测 <!doctype html> <html> <head> <meta charset="utf-8"> <title& ...
- PowerPoint幻灯片手动翻页设置技巧
步骤: 幻灯片放映>设置幻灯片放映>手动
- Linux从入门到适应(三):Ubuntu16.04将python从3.5升级到3.6
1 将python从默认的python2.7更换为python3.5 : sudo update-alternatives --install /usr/bin/python python /usr/ ...
- vijos1382寻找主人
题目大意: 给出两个串(长度<=1e6),问是否同构,如果同构输出最小表示. 题解: 这是最小表示法模板题.在这里好好讲一下最小表示法. 首先有一个最暴力的方法:把所有表示搞出来排序. 时间复杂 ...
- [Python3网络爬虫开发实战] 3.1-使用urllib
在Python 2中,有urllib和urllib2两个库来实现请求的发送.而在Python 3中,已经不存在urllib2这个库了,统一为urllib,其官方文档链接为:https://docs.p ...
- [Python3网络爬虫开发实战] 1.6.2-Tornado的安装
Tornado是一个支持异步的Web框架,通过使用非阻塞I/O流,它可以支撑成千上万的开放连接,效率非常高,本节就来介绍一下它的安装方式. 1. 相关链接 GitHub:https://github. ...
- mysql常用命令用法
Mysql帮助文档地址:http://dev.mysql.com/doc/ 1.创建数据库: create database database_name; 2.选择数据库: use database_ ...
- FreeRTOS--疑难杂症
花了3个晚上,把这个章节看完,受益匪浅. 最有用的应该是与中断相关的错误,优先排查中断优先级设置. 堆栈溢出检查,可能用到,一般先把堆栈设置的足够大,只要没有溢出就是好事,溢出了,掌握了栈溢出钩子函数 ...
- Springboot 缓存使用
. CachingProvider . CacheManager . Cache . Entry . Expiry 1. 开启基于注解的缓存 @EnableCaching 下面列出几个核心的注解 @C ...
- Qt Widgets Application可执行程序发布方式
前言 写好的Qt程序想打包发布,之前按照Qt快速入门系列教程里的方法,直接选release,构建,之后找到exe,拷贝几个dll,然而报错如图: 后来找到教程:http://tieba.baidu.c ...