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 编程练习的更多相关文章

  1. 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 ...

  2. C Primer Plus 第10章 数组和指针 编程练习

    这章感觉好难啊,放个别人的总结. // 多维数组和指针 #include <stdio.h> int main(void) { int zippo[4][2] = {{2, 4}, {6, ...

  3. C Primer Plus_第9章_函数_编程练习

    1.题略 /*返回较小值,设计驱动程序测试该函数*/ #include <stdio.h> double min (double a, double b); int main (void) ...

  4. C Primer Plus_第四章_字符串和格式化输入输出_编程练习

    Practice 1.输入名字和姓氏,以"名字,姓氏"的格式输出打印. #include int main(void) { char name[20]; char family[2 ...

  5. C Primer Plus_第5章_运算符、表达式和语句_编程练习

    Practice 1. 输入分钟输出对应的小时和分钟. #include #define MIN_PER_H 60 int main(void) { int mins, hours, minutes; ...

  6. Laxcus大数据管理系统2.0(5)- 第三章 数据存取

    第三章 数据存取 当前的很多大数据处理工作,一次计算产生几十个GB.或者几十个TB的数据已是正常现象,驱动数百.数千.甚至上万个计算机节点并行运行也已经不足为奇.但是在数据处理的后面,对于这种在网络间 ...

  7. 《驾驭Core Data》 第三章 数据建模

    本文由海水的味道编译整理,请勿转载,请勿用于商业用途.    当前版本号:0.1.2 第三章数据建模 Core Data栈配置好之后,接下来的工作就是设计对象图,在Core Data框架中,对象图被表 ...

  8. TMS320C54x系列DSP的CPU与外设——第5章 数据寻址

    第5章 数据寻址 C54x DSP提供7种基本寻址方式. ■ Immediate addressing uses the instruction to encode a fixed value.    ...

  9. C和指针 (pointers on C)——第三章——数据

    第三章 数据 本章是非常重要的,在特定范围内使用.链接属性.存储类型.const.extern和statickeyword使用.几乎所有的公司是C++在采访的第一个问题. 总结: 具有external ...

随机推荐

  1. 让backspace键默认为删除键

    在/root/.bashrc  中插入一条: stty erase ^H

  2. 《服务器的追踪与审计》RHEL6

    在linux系统/etc目录下有两个文件: 服务器的追踪: 当其他人访问我的主机时,通过日志监控到那台主机什么时间通过什么方式登陆,做什么?

  3. mount.nfs: access denied by server while mounting localhost:/home/xuwq/minilinux/system

    在执行命令如下: mount -t nfs localhost:/home/xuwq/minilinux/system /mnt 出现的错误: mount.nfs: access denied by ...

  4. nginx总结

    kill int 2333  进程号   停止程序 kiil quit 2322  优雅停止服务 kill -HUP 2333  优雅重启 从新读取配置文件 kill -HUP 'cat logs/n ...

  5. MongoDB 备份方法

    翻译自 http://docs.mongodb.org/manual/core/backups/ 有以下几种方法来备份MongoDB群集: 通过复制底层数据文件来备份 通过mongodump来备份 通 ...

  6. php威盾解密的例子分享

    例子,批量解密  代码如下 复制代码 <?php/************************************威盾PHP加密专家解密算法 By:zhrt*http://www.111 ...

  7. 【转】为什么我说 Android 很糟糕

    http://zhuanlan.zhihu.com/wooyun/19879016 Android 的安全问题一直被吐槽,包括不安全的APP市场.上次的远程命令执行漏洞.还有它的权限机制,总之一团糟, ...

  8. 查看MySQL还原出来的binlog日志中内容方法

    用mysqlbinlog查出需要查看的数据后,可以用more来查看: [root@yoon data]# more recover_sakila.sql | grep --ignore-case -E ...

  9. backbone collection add 事件回调参数

    this.listenTo(this.collection, 'add', this.renderBook); renderBook: function (item) { var bookView = ...

  10. 关于C与C++的struct,union,enum用法差异

    对着代码说话: #include <stdio.h> #include <stdlib.h> struct test { int abc; }; enum _enum {A,B ...