好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

CPrimerPlus(第五版)全书源代码.pdf

70页
  • 卖家[上传人]:ali****an
  • 文档编号:118826037
  • 上传时间:2019-12-26
  • 文档格式:PDF
  • 文档大小:736.30KB
  • / 70 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • // 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 are %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("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 writeable 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 16-bit signed variable me16 = 4593; printf("First, assume int16_t is short: "); printf("me16 = %hd\n", 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 #include int main(void) { int x = 100; printf("dec = %d; octal = %o; hex = %x\n", x, x, x); printf("dec = %d; octal = %#o; hex = %#x\n", 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"); 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 %d\n", ten, 2, ten - two ); printf("Doing it wrong: "); printf("%d minus %d is %d\n", ten ); // 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 整型ho 为八进制形式 printf("un = %u and not %d\n", un, un); printf("end = %hd and %d\n", end, end); printf("big = %ld and not %hd\n", big, big); printf("verybig= %lld and not %ld\n", verybig, verybig); return 0; } */ ////////////////////////////////////////////////////////////// /* showf_pt.c -- displays float value in two ways */ /* #include int main(void) { float aboat = 32000.0; double abet = 2.14e9; long double dip = 5.32e-5; printf("%f can be written %e\n", aboat, aboat); printf("%f can be written %e\n", abet, abet); printf("%f can be written %e\n", dip, dip); return 0; } */ ////////////////////////////////////////////////////////////// /* toobig.c-exceeds maximum int size on our system */ /* #include int main(void) { int i = 2147483647; unsigned int j = 4294967295; printf("%d %d %d\n", i, i+1, i+2); printf("%u %u %u\n", 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; } */ //////////////////////////////////////////////。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.