4

Display a F°/C° conversion table

  1. #include <stdio.h>
  2.  
  3. /* print Fahrenheit-Celsius table
  4.    for fahr = 0, 20, ..., 300 */
  5. #define LOW     0
  6. #define HIGH    300
  7. #define STEP    20
  8.  
  9. main() {
  10.     int fahr, celsius;
  11.     int low = LOW;          /* lower limit of temperature  */
  12.     int high = HIGH;        /* upper limit */
  13.     int step = STEP;        /* step size */
  14.  
  15.     fahr = low;
  16.     while( fahr <= high ) {
  17.         celsius = 5 * (fahr-32) / 9;
  18.         printf("%d\t%d\n", fahr, celsius);
  19.         fahr = fahr + step;
  20.     }
  21. }
$ gcc -o fahrencel1 fahrencel1.c
$ ./fahrencel1
0	-17
20	-6
40	4
60	15
80	26
100	37
120	48
140	60
160	71
180	82
200	93
220	104
240	115
260	126
280	137
300	148
  1. #include <stdio.h>
  2.  
  3. /* Print Fahrenheit-Celsius table. */
  4.  
  5. #define LOW     0
  6. #define HIGH    300
  7. #define STEP    20
  8.  
  9. main() {
  10.     int fahr;
  11.  
  12.     for( fahr = LOW; fahr <= HIGH; fahr += STEP )
  13.         printf("%3d\t%6.2f\n", fahr, (5.0/9.0) * (fahr-32));
  14. }
$ gcc -o fahrencel fahrencel.c
$ ./fahrencel
  0	-17.78
 20	 -6.67
 40	  4.44
 60	 15.56
 80	 26.67
100	 37.78
120	 48.89
140	 60.00
160	 71.11
180	 82.22
200	 93.33
220	104.44
240	115.56
260	126.67
280	137.78
300	148.89

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].