大小: 1111
备注:
|
大小: 2654
备注:
|
删除的内容标记成这样。 | 加入的内容标记成这样。 |
行号 46: | 行号 46: |
{{{#!cplusplus /*Exercise 1-4. Write a program to print the corresponding Celsius to Fahrenheit table.*/ #include <stdio.h> /* print Celsius-Fahrenheit table for celsius = 0, 20, ..., 300; floating-point version */ main() { float fahr, celsius; int lower, upper, step; lower = 0; /* lower limit of temperatuire scale */ upper = 300; /* upper limit */ step = 20; /* step size */ celsius = lower; while (celsius <= upper) { fahr = celsius * (9.0/5.0) + 32.0; printf("%3.0f %6.1f\n", celsius, fahr); celsius = celsius + step; } } }}} {{{#!cplusplus /*Exercise 1-5. Modify the temperature conversion program to print the table in reverse order, that is, from 300 degrees to 0.*/ #include <stdio.h> /* print Fahrenheit-Celsius table for fahr = 300, 280, ..., 0; floating-point version */ main() { int fahr; for(fahr = 300; fahr >= 0; fahr = fahr - 20) printf("%3d %6.1f\n", fahr, (5.0/9.0)*(fahr-32)); } }}} {{{#!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-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 }