Page 52 - Programming Microcontrollers in C
P. 52
Program Flow and Control 37
i = guess;
guess = (i + (10000/i))/2;
}
printf(“The square root of 10000 is
%d\n”,guess);
return 0;
}
As in the first example, the #include statement is used to bring
standard input/output features into the program, and the program
starts with the function definition main(). Inside of the main pro
gram, the first statement is
int guess,i;
This statement defines the variables guess and i as integers. No
value is assigned to i at this time, but a space in memory is allocated
to guess and i and the space is sufficient to store an integer. The
first executable statement in the program is
i=1;
This statement is called an assignment statement. The equal sign here
is a misnomer. The statement is read “replace the contents of the
memory location assigned to i with a 1.’’ The next statement
guess = 5;
assigns a value 5 to the variable guess. The statement
while(guess != i)
invokes a looping operation. The while operation will cause the
statement following to execute repeatedly. At the beginning of each
loop execution, the while argument guess!=i is checked. This
argument is read “guess is not equal to i.” So long as this argument is
TRUE, the statement following the while will be executed. When
guess becomes equal to i, the statement following the while will
be skipped.
The while is followed by a compound statement that contains
two statements:
{
i=guess;