CPrimerPlus(第五版)全书源代码

上传人:ali****an 文档编号:118826037 上传时间:2019-12-26 格式:PDF 页数:70 大小:736.30KB
返回 下载 相关 举报
CPrimerPlus(第五版)全书源代码_第1页
第1页 / 共70页
CPrimerPlus(第五版)全书源代码_第2页
第2页 / 共70页
CPrimerPlus(第五版)全书源代码_第3页
第3页 / 共70页
CPrimerPlus(第五版)全书源代码_第4页
第4页 / 共70页
CPrimerPlus(第五版)全书源代码_第5页
第5页 / 共70页
点击查看更多>>
资源描述

《CPrimerPlus(第五版)全书源代码》由会员分享,可在线阅读,更多相关《CPrimerPlus(第五版)全书源代码(70页珍藏版)》请在金锄头文库上搜索。

1、/ chapter 01 /* #include int main(void) int dogs; printf(How many dogs do you have?n); scanf(%d, printf(So you have %d dog(s)!n, dogs); return 0; */ / / /chapter 02 / fathm_ft.c - converts 2 fathoms to feet /* #include int main(void) int feet, fathoms; fathoms = 2; feet = 6 * fathoms; printf(There a

2、re %d feet in %d fathoms!n, feet, fathoms); printf(Yes, I said %d feet!n, 6 * fathoms); return 0; */ / /* #include int main(void) / a simple program int num; / define a variable called num num = 1; / assign a value to num printf(I am a simple ); / use the printf() function printf(computer.n); printf

3、(My favorite number is %d because it is first.n,num); return 0; */ / / two_func.c - a program using two functions in one file /* #include void butler(void); / ISO/ANSI C function prototyping int main(void) printf(I will summon the butler function.n); butler(); printf(Yes. Bring me some tea and write

4、able CD-ROMS.n); return 0; void butler(void) / start of function definition printf(You rang, sir?n); */ / / /chapter 03 数据和 C /* / altnames.c - portable names for integer types #include #include / supports portable types the system doesnt contain the header file int main(void) int16_t me16; / me16 a

5、 16-bit signed variable me16 = 4593; printf(First, assume int16_t is short: ); printf(me16 = %hdn, me16); printf(Next, lets not make any assumptions.n); printf(Instead, use a macro from inttypes.h: ); printf(me16 = % PRId16 n, me16); return 0; */ / /* / bases.c-prints 100 in decimal, octal, and hex

6、#include int main(void) int x = 100; printf(dec = %d; octal = %o; hex = %xn, x, x, x); printf(dec = %d; octal = %#o; hex = %#xn, x, x, x); /%# 十六进制前显示 Ox /八进制数前显示 o return 0; */ / /* / charcode.c-displays code number for a character #include int main(void) char ch; printf(Please enter a character.n)

7、; scanf(%c, printf(The code for %c is %d.n, ch, ch); return 0; */ / /* /print1.c-displays some properties of printf() #include int main(void) int ten = 10; int two = 2; printf(Doing it right: ); printf(%d minus %d is %dn, ten, 2, ten - two ); printf(Doing it wrong: ); printf(%d minus %d is %dn, ten

8、); / forgot 2 arguments return 0; */ / /* print2.c-more printf() properties */ /* #include int main(void) unsigned int un = 3000000000; / system with 32-bit int short end = 200; / and 16-bit short long big = 65537; long verybig = 12345678908642; /C 也可以使用前缀 h 来表示 short 类型。 /因此%hd 显示一个十进制的 short 整型。%h

9、o 为八进制形式。 printf(un = %u and not %dn, un, un); printf(end = %hd and %dn, end, end); printf(big = %ld and not %hdn, big, big); printf(verybig= %lld and not %ldn, verybig, verybig); return 0; */ / /* showf_pt.c - displays float value in two ways */ /* #include int main(void) float aboat = 32000.0; dou

10、ble abet = 2.14e9; long double dip = 5.32e-5; printf(%f can be written %en, aboat, aboat); printf(%f can be written %en, abet, abet); printf(%f can be written %en, dip, dip); return 0; */ / /* toobig.c-exceeds maximum int size on our system */ /* #include int main(void) int i = 2147483647; unsigned

11、int j = 4294967295; printf(%d %d %dn, i, i+1, i+2); printf(%u %u %un, j, j+1, j+2); return 0; */ / /* typesize.c - prints out type sizes */ /* #include int main(void) / c99 provides a %zd specifier for sizes printf(Type int has a size of %u bytes.n, sizeof(int); /4 bytes printf(Type char has a size of %u bytes.n, sizeof(char);/ 1 bytes printf(Type long has a size of %u bytes.n, sizeof(long);/4 bytes printf(Type double has a size of %u bytes.n, sizeof(double);/8 bytes return 0; */ /

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号