Page 23 - Programming Microcontrollers in C
P. 23

8      Chapter 1  Introduction to C

                          of course, is less than 11, so the statement following the while will
                          be executed again and new values will be printed to the screen. This
                          sequence will be repeated until the incremented value for i equals
                          11, at which time i<11 will be FALSE. At that point in the pro­
                          gram, the statement following the while will be skipped, and the
                          program will have reached its end. The result of executing the above
                          program is shown in the following table:
               i          i          i
                          squared  cubed


               1          1          1
               2          4          8
               3          9          27
               4          16         64
               5          25         125
               6          36         216
               7          49         343
               8          64         512
               9          81         729
               10         100        1000

                          EXERCISES

                          1. Write, compile, and execute each of the example programs shown
                            in this section.

                          2. Write a program to calculate the Fahrenheit temperature for the Cel­
                            sius values between 0° degrees and 100° in steps of 10° each. The
                            conversion formula is F=9*C/5+32. Use integer variables, and ex­
                            amine the result when you use F=C*(9/ 5) + 32. What went wrong?


            Names

                              Variables, constants and functions in C are named, and the pro­
                          gram controls operations on these named variables and constants.
                          Variables and constants are called operands. Names can be as many
                          as 31 characters long. The characters that make up the name can be
                          the upper and the lower case letters, the digits 0 through 9, and the
                          underscore character ‘_’. There are several defined constants and
                          functions that are used by the compiler. All of these names begin
   18   19   20   21   22   23   24   25   26   27   28