4.10 Exercises 4. Write programs to calculate: a. the area of a circle of radius 10 m, Chapter 4 : Simple Programs 85 b. the annual interest payable on a loan of $5365.25 at 12.5%, and c. the sales tax payable at 7% on a purchase of $12.50. In the last two examples the answers are not rounded off to the nearest cent. You can force this by indicating not only the field size but the numbers of decimal places to be output. For example, put 1.66666 : 5 : 2 will produce °1.67. The 2 indicates that you want 2 decimal places. The last decimal digit is rounded off. Change the programs for parts b and c to output values to the nearest cent. 5. Experiment to see what happens when you specify a field size which is too small to hold a number. For example, try this program. put "How many digits ", 1 / 3 : 5 put "What about this?": 8 6. What happens when you work with very big numbers? Try this example put 32516 * 578632.0 Try others. When the result is output, it is in the exponent form, often used in science. Try leaving the decimal point off the second number. 7. What happens when you work with very small numbers. Try this example put 0.0000003 * 0.000006 Try others. The exponents or powers of 10 are negative. 8. Try a program with the ** arithmetic operator put 7 ** 2, " is the same as ", 7 * 7 The ** is the operator for exponentiation. Try other examples. 9. Use the exponent form of real numbers in an arithmetic expression. For example, put 6e5 + 2e2, " is the same as ", 600000 + 200 When is the answer output in exponent form? Experiment using other examples. 10.In Turing there are a number of mathematical functions predefined in the language. Try this put "The square root of 49 is ", sqrt (49) The sqrt function produces the square root of what follows in parentheses. Try this put sqrt (371 ** 2) Experiment with the square root function. |