大小: 1294
备注:
|
大小: 1977
备注:
|
删除的内容标记成这样。 | 加入的内容标记成这样。 |
行号 58: | 行号 58: |
{{{#!cplusplus /* Author: czk Email: [email protected] Date: 20-12-05 21:30 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; } } }}} |
1 /*
2 Author: czk
3 Email: [email protected]
4 Date: 20-12-05 21:30
5 Exercise 1-3. Modify the temperature conversion program to print a heading above the table.*/
6 #include <stdio.h>
7
8 /* print Fahrenheit-Celsius table
9 for fahr = 0, 20, ..., 300; floating-point version */
10 main()
11 {
12 float fahr, celsius;
13 int lower, upper, step;
14
15 lower = 0; /* lower limit of temperatuire scale */
16 upper = 300; /* upper limit */
17 step = 20; /* step size */
18
19 printf("fahr celsius\n");
20
21 fahr = lower;
22 while (fahr <= upper) {
23 celsius = (5.0/9.0) * (fahr-32.0);
24 printf("%4.0f %7.1f\n", fahr, celsius);
25 fahr = fahr + step;
26 }
27 }
1 /*
2 Author: czk
3 Email: [email protected]
4 Date: 20-12-05 21:30
5 Exercise 1-4. Write a program to print the corresponding Celsius to Fahrenheit table.*/
6 #include <stdio.h>
7
8 /* print Celsius-Fahrenheit table
9 for celsius = 0, 20, ..., 300; floating-point version */
10 main()
11 {
12 float fahr, celsius;
13 int lower, upper, step;
14
15 lower = 0; /* lower limit of temperatuire scale */
16 upper = 300; /* upper limit */
17 step = 20; /* step size */
18
19 celsius = lower;
20 while (celsius <= upper) {
21 fahr = celsius * (9.0/5.0) + 32.0;
22 printf("%3.0f %6.1f\n", celsius, fahr);
23 celsius = celsius + step;
24 }
25 }