版本4和5间的区别
于2005-12-20 21:36:09修订的的版本4
大小: 2144
编辑: czk
备注:
于2005-12-20 21:38:54修订的的版本5
大小: 2654
编辑: czk
备注:
删除的内容标记成这样。 加入的内容标记成这样。
行号 76: 行号 76:
行号 85: 行号 84:

{{{#!cplusplus
/*Exercsise 1-6. Verify that the expression getchar() != EOF is 0 or 1.*/
#include <stdio.h>

/* Verify that the expression getchar() != EOF is 0 or 1. */
main()
{
    int c;
    
    while(c = (getchar() !=EOF))
        printf("%d\n", c);
    printf("%d\n", c);
}
}}}

{{{#!cplusplus
/*Exercsise 1-6. Verify that the expression getchar() != EOF is 0 or 1.*/
#include <stdio.h>

/* Write a program to print the value of EOF. */
main()
{
    printf("%d\n", EOF);
}

}}}

   1 /*Exercise 1-1. Run the "hello, world" program on your system. Experiment with leaving out parts of the program, to see what error messages you get.*/
   2 #include <stdio.h>
   3 
   4 main()
   5 {
   6     printf("hello, world\n");
   7 }

   1 /*Exercise 1-2. Experiment to find out what happens when prints's argument string contains \c, where c is some character not listed above.*/
   2 #include <stdio.h>
   3 
   4 main()
   5 {
   6     printf("\a");
   7 }

   1 /*Exercise 1-3. Modify the temperature conversion program to print a heading above the table.*/
   2 #include <stdio.h>
   3 
   4 /* print Fahrenheit-Celsius table
   5 for fahr = 0, 20, ..., 300; floating-point version */
   6 main()
   7 {
   8     float fahr, celsius;
   9     int lower, upper, step;
  10     
  11     lower = 0; /* lower limit of temperatuire scale */
  12     upper = 300; /* upper limit */
  13     step = 20; /* step size */
  14     
  15     printf("fahr celsius\n");
  16     
  17     fahr = lower;
  18     while (fahr <= upper) {
  19         celsius = (5.0/9.0) * (fahr-32.0);
  20         printf("%4.0f %7.1f\n", fahr, celsius);
  21         fahr = fahr + step;
  22     }
  23 }

   1 /*Exercise 1-4. Write a program to print the corresponding Celsius to Fahrenheit table.*/
   2 #include <stdio.h>
   3 
   4 /* print Celsius-Fahrenheit table
   5 for celsius = 0, 20, ..., 300; floating-point version */
   6 main()
   7 {
   8     float fahr, celsius;
   9     int lower, upper, step;
  10     
  11     lower = 0; /* lower limit of temperatuire scale */
  12     upper = 300; /* upper limit */
  13     step = 20; /* step size */
  14     
  15     celsius = lower;
  16     while (celsius <= upper) {
  17         fahr =  celsius * (9.0/5.0) + 32.0;
  18         printf("%3.0f %6.1f\n", celsius, fahr);
  19         celsius = celsius + step;
  20     }
  21 }

   1 /*Exercise 1-5. Modify the temperature conversion program to print the table in reverse order, that is, from 300 degrees to 0.*/
   2 #include <stdio.h>
   3 
   4 /* print Fahrenheit-Celsius table
   5 for fahr = 300, 280, ..., 0; floating-point version */
   6 main()
   7 {
   8     int fahr;
   9    
  10     for(fahr = 300; fahr >= 0; fahr = fahr - 20)
  11         printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32));
  12 }

   1 /*Exercsise 1-6. Verify that the expression getchar() != EOF is 0 or 1.*/
   2 #include <stdio.h>
   3 
   4 /* Verify that the expression getchar() != EOF is 0 or 1. */
   5 main()
   6 {
   7     int c;
   8     
   9     while(c = (getchar() !=EOF))
  10         printf("%d\n", c);
  11     printf("%d\n", c);
  12 }

   1 /*Exercsise 1-6. Verify that the expression getchar() != EOF is 0 or 1.*/
   2 #include <stdio.h>
   3 
   4 /* Write a program to print the value of EOF. */
   5 main()
   6 {
   7     printf("%d\n", EOF);
   8 }

Answer_to_Chapter_1 (2008-02-23 15:34:13由localhost编辑)

ch3n2k.com | Copyright (c) 2004-2020 czk.