c primer plus 第五版书上源码(更新)

例2.1

Code   ViewPrint
·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
  1. #include "stdafx.h"
  2. int _tmain(int argc, _TCHAR* argv[])
  3. {
  4.     int num;
  5.     num =1;
  6.     printf("I am a sipmle ");
  7.     printf("computer.\n");
  8.     printf("My favorite number is %d because it is first.\n",num);
  9.     getchar();
  10.     return 0;
  11. }

例2.2 fathm_ft.c

Code   ViewPrint
·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
  1. #include "stdafx.h"
  2. int _tmain(int argc, _TCHAR* argv[])
  3. {
  4.     int feet,fathoms;
  5.     fathoms = 2;
  6.     feet = 6 * fathoms;
  7.     printf("There are %d feet in %d fathoms!\n",feet,fathoms);
  8.     printf("Yes,I said %d feet!\n",6 * fathoms);
  9.     getchar();
  10.     return 0;
  11. }

例2.3 two_func.cpp

Code   ViewPrint
·········10········20········30········40········50········60········70········80········90········100·······110·······120·······130·······140·······150
  1. #include "stdafx.h"
  2. void butler(void);
  3. int _tmain(int argc, _TCHAR* argv[])
  4. {
  5.     printf("I will summon the butler function.\n");
  6.     butler();
  7.     printf("Yes.Bring me some tea and writeable CD-ROMS.\n");
  8.     getchar();
  9.     return 0;
  10. }
  11. void butler(void)
  12. {
  13.     printf("You rang.sir?\n");
  14. }

程序清单 3.4 print2.c 程序

  1. // print2.cpp : 定义控制台应用程序的入口点。
  2. //第三章 数据和c 代码 程序清单 3.4 print2.c 程序
  3. #include "stdafx.h"
  4. int _tmain(int argc, _TCHAR* argv[])
  5. {
  6.     unsigned int un = 3000000000;
  7.     short end = 200;
  8.     long big = 65537; long long verybig = 12345678908642;
  9.     printf("un %u and not %d\n",un,un);
  10.     printf("end =%hd and %d\n",end,end);
  11.     printf("big = %ld and not %hd\n",big,big);
  12.     printf("verybig= %lld and not %ld\n",verybig,verybig);
  13.     getchar();
  14.     return 0;
  15. }

程序清单 3.5 charcode.c 程序  

  1. // charcode.cpp : 定义控制台应用程序的入口点。
  2. //第三章 数据和c 代码 程序清单 3.5 charcode.c 程序  
  3. #include "stdafx.h"
  4. int _tmain(int argc, _TCHAR* argv[])
  5. {
  6.     char ch;
  7.     printf("Please enter a character.\n");
  8.     scanf("%c",&ch);//用户输入字符
  9.     printf("The code for %c is %d.\n",ch,ch);
  10.     getchar();
  11.     getchar();
  12.     return 0;
  13. }