which set the variables to their initial values. Individual statements are terminated by semicolons.
Each line of the table is computed the same way, so we use a loop that repeats once per output line; this is the
purpose of the while loop
while (fahr <= upper) {
...
}
The while loop operates as follows: The condition in parentheses is tested. If it is true (fahr is less than or equal
to upper), the body of the loop (the three statements enclosed in braces) is executed. Then the condition is re-
tested, and if true, the body is executed again. When the test becomes false (fahr exceeds upper) the loop ends,
and execution continues at the statement that follows the loop. There are no further statements in this program, so
it terminates.
The body of a while can be one or more statements enclosed in braces, as in the temperature converter, or a
single statement without braces, as in
while (i < j)
i = 2 * i;
In either case, we will always indent the statements controlled by the while by one tab stop (which we have
shown as four spaces) so you can see at a glance which statements are inside the loop. The indentation emphasizes
the logical structure of the program. Although C compilers do not care about how a program looks, proper
indentation and spacing are critical in making programs easy for people to read. We recommend writing only one
statement per line, and using blanks around operators to clarify grouping. The position of braces is less important,
although people hold passionate beliefs. We have chosen one of several popular styles. Pick a style that suits you,
then use it consistently.
Most of the work gets done in the body of the loop. The Celsius temperature is computed and assigned to the
variable celsius by the statement
celsius = 5 * (fahr-32) / 9;
The reason for multiplying by 5 and dividing by 9 instead of just multiplying by 5/9 is that in C, as in many other
languages, integer division truncates: any fractional part is discarded. Since 5 and 9 are integers. 5/9 would be
truncated to zero and so all the Celsius temperatures would be reported as zero.
This example also shows a bit more of how printf works. printf is a general-purpose output formatting
function, which we will describe in detail in
Chapter 7. Its first argument is a string of characters to be printed,
with each % indicating where one of the other (second, third, ...) arguments is to be substituted, and in what form it
is to be printed. For instance, %d specifies an integer argument, so the statement
printf("%d\t%d\n", fahr, celsius);
http://freebooks.by.ru/view/CProgrammingLanguage/chapter1.html(6of30)[9/6/200212:21:11]