C Primer Plus 第3章 数据和C 编程练习
1、
- /* 整数上溢 */
- #include <stdio.h>
- int main(void)
- {
- int i = ;
- unsigned int j = ;
- /*
- 无符号整数j像一个汽车里程指示表(形容的太好了,可参考《计算机科学导论》第3章 数据存储,有图),
- 当达到最大值时,它将溢出到起始点。整数i也是同样。它们的主要区别是unsigned int变量j的起始点是0(正像里程
- 指示表那样),而int变量i的起始点则是-2147483648。——参考《C Primer Plus》
- */
- printf("%d %d %d\n", i, i+, i+);
- printf("%u %u %u\n", j, j+, j+);
- return ;
- }
浮点数上溢和浮点数下溢,于浮点数,以目前的知识最终是无法深究的,故留待以后探索。只能借《C Primer Plus》之意:
当计算结果是一个大得不能表达的数时,会发生上溢。现在C语言要求为这样的数赋予一个代表无穷大的特殊值,以inf或infinity示之。
用对浮点值可用的全部精度进行表示的最小数字(它具有最小的指数,并且仍具有可以由全部可用位进行表示的最小的尾数值),若此数除以2,通常这个操作将使指数部分减小,但是指数已经达到了最小值,所以计算机只好将尾数部分达到位进行右移,空出首位二进制位,并丢弃最后一位二进制位。此过程称为下溢。(举例说之:以十进制为例,把一个包含4位有效数字的数0.1234E-10除以10,将得到结果0.0123E-10,但是损失了1位有效数字)。
- /* 浮点数上溢与下溢 */
- #include <stdio.h>
- int main(void)
- {
- float toobig = 3.4e38 * 100.0f;
- float toosmall = 0.1234e-2 / ;
- printf("%e\n", toobig); // 输出为inf
- printf("%f\n", toosmall); // 损失1位有效数字
- return ;
- }
2、
- #include <stdio.h>
- int main(void)
- {
- int ch;
- printf("请输入一个ASCII码值: ");
- scanf("%d", &ch);
- printf("%d相应的字符为: %c", ch, ch);
- return ;
- }
3、
- #include <stdio.h>
- int main(void)
- {
- printf("\aStartled by the sudden sound, Sally shouted, ");
- printf("\"By the Great Pumpkin, what was that! \"\n");
- return ;
- }
4、
- #include <stdio.h>
- int main(void)
- {
- float input;
- printf("请输入一个浮点数: ");
- scanf("%f", &input);
- printf("The input is %f or %e.", input, input);
- return ;
- }
5、
- #include <stdio.h>
- int main(void)
- {
- int age;
- printf("请输入您的年龄: ");
- scanf("%d", &age);
- printf("您的年龄合%e秒", age * 3.156e7);
- return ;
- }
6、
- #include <stdio.h>
- int main(void)
- {
- int kua;
- printf("请输入水(单位为夸脱)的夸脱数: ");
- scanf("%d", &kua);
- printf("%d夸脱水中包含%e个水分子", kua, kua * / 3.0e-23);
- return ;
- }
7、
- #include <stdio.h>
- int main(void)
- {
- float feet;
- printf("请输入您的身高(单位为英寸): ");
- scanf("%f", &feet);
- printf("%.2f inches = %.2f cm", feet, feet * 2.54);
- return ;
- }
C Primer Plus 第3章 数据和C 编程练习的更多相关文章
- C Primer Plus_第6章_循环_编程练习
1.题略 #include int main(void) { int i; char ch[26]; for (i = 97; i <= (97+25); i++) { ch[i-97] = i ...
- C Primer Plus 第10章 数组和指针 编程练习
这章感觉好难啊,放个别人的总结. // 多维数组和指针 #include <stdio.h> int main(void) { int zippo[4][2] = {{2, 4}, {6, ...
- C Primer Plus_第9章_函数_编程练习
1.题略 /*返回较小值,设计驱动程序测试该函数*/ #include <stdio.h> double min (double a, double b); int main (void) ...
- C Primer Plus_第四章_字符串和格式化输入输出_编程练习
Practice 1.输入名字和姓氏,以"名字,姓氏"的格式输出打印. #include int main(void) { char name[20]; char family[2 ...
- C Primer Plus_第5章_运算符、表达式和语句_编程练习
Practice 1. 输入分钟输出对应的小时和分钟. #include #define MIN_PER_H 60 int main(void) { int mins, hours, minutes; ...
- Laxcus大数据管理系统2.0(5)- 第三章 数据存取
第三章 数据存取 当前的很多大数据处理工作,一次计算产生几十个GB.或者几十个TB的数据已是正常现象,驱动数百.数千.甚至上万个计算机节点并行运行也已经不足为奇.但是在数据处理的后面,对于这种在网络间 ...
- 《驾驭Core Data》 第三章 数据建模
本文由海水的味道编译整理,请勿转载,请勿用于商业用途. 当前版本号:0.1.2 第三章数据建模 Core Data栈配置好之后,接下来的工作就是设计对象图,在Core Data框架中,对象图被表 ...
- TMS320C54x系列DSP的CPU与外设——第5章 数据寻址
第5章 数据寻址 C54x DSP提供7种基本寻址方式. ■ Immediate addressing uses the instruction to encode a fixed value. ...
- C和指针 (pointers on C)——第三章——数据
第三章 数据 本章是非常重要的,在特定范围内使用.链接属性.存储类型.const.extern和statickeyword使用.几乎所有的公司是C++在采访的第一个问题. 总结: 具有external ...
随机推荐
- 用泛型的IEqualityComparer<T>接口去重复项
提供者:porschev 题目:下列数据放在一个List中,当ID和Name都相同时,去掉重复数据 ID Name 1 张三 1 李三 1 小伟 1 李三 2 李四 2 李武 ----- ...
- hdu 2256 Problem of Precision 构造整数 + 矩阵快速幂
http://acm.hdu.edu.cn/showproblem.php?pid=2256 题意:给定 n 求解 ? 思路: , 令 , 那么 , 得: 得转移矩阵: 但是上面求出来的并 ...
- Jquer Ajax xmlhttp请求成功了,为什么一直在error函数里面
转载自http://www.cnblogs.com/sky_Great/archive/2013/01/18/2866861.html 并进行整理: 今天遇到了一个极其奇怪的问题,用各种工具检查都能看 ...
- [转]DataGridView绑定泛型List的种种
1.DataGridView数据绑定对比(DataTable与泛型List):当DataGridView的DataSource是DataTable的时候,DataTable的数据改变时,DataGri ...
- ThinkPHP中PATHINFO模式优化
ThinkPHP 3.1.2官方手册 第16.2章节 <隐藏index.php>中提到在Ngnix中隐藏index.php实现SEO友好的方法,其中使用了如下的代码 location / ...
- GGS: Sybase to Oracle
Step 1: Start the GGSCI on Source and Target Source Target Oracle GoldenGate Command Interpreter for ...
- (转) java 复制文件,不使用输出流复制,高效率,文件通道的方式复制文件
public static void fileChannelCopy(File s, File t) { FileInputStream fi = null; FileOutputStream fo ...
- Linux 系统 网络配置
Linux 系统 网络配置 配置Linux系统网络的方法有几种,这里介绍本人常用的两种. 第一种:使用命令ifconfig配置,具体用法:Ipconfig ethx x.x.x.x net ...
- 网络笔记01-3 socket 实现百度页面的两种方式
scoket 实现百度页面的两种方式: 1.利用系统自带 //1.创建URL NSURL *url=[NSURL URLWithString:@"http://m.baidu.com& ...
- 【BZOJ 1188】 [HNOI2007]分裂游戏
Description 聪聪和睿睿最近迷上了一款叫做分裂的游戏. 该游戏的规则试: 共有 n 个瓶子, 标号为 0,1,2.....n-1, 第 i 个瓶子中装有 p[i]颗巧克力豆,两个人轮流取豆子 ...