Saturday 25 January 2014

C PROGRAMMS

Variables and Arithmetic Expressions
The next program uses the formula oC=(5/9)(oF-32) to print the following table of Fahrenheit temperatures and
their centigrade or Celsius equivalents:
1 -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
#include <stdio.h>
/* print Fahrenheit-Celsius table
for fahr = 0, 20, ..., 300 */
main()
{
int fahr, celsius;
int lower, upper, step;
lower = 0; /* lower limit of temperature scale */
upper = 300; /* upper limit */
step = 20; /* step size */
fahr = lower;
Chapter 1 - A Tutorial Introduction
while (fahr <= upper) {
celsius = 5 * (fahr-32) / 9;
printf("%d\t%d\n", fahr, celsius);
fahr = fahr + step;
}
}
The two lines
/* print Fahrenheit-Celsius table
for fahr = 0, 20, ..., 300 */

No comments:

Post a Comment

 

FACEBOOK PAGE

SKETCHES & PAINTINGS