# Project 2

## Due: Wednesday, October 11, 1995

### Objective

The objective of this project is to practice writing programs with nested for loops.

### Project Policy Reminder

It has been the stated policy of this class, that you are not to work on the projects together. While you may ask your classmates for help with simple debugging and for tips on using UNIX, any assistance in developing the program must not come from your classmates. Again, this means you are not to have a printed or electronic copy (or access to an electronic copy) of a classmate's programs. This is considered cheating. If your classmate is looking at the screen while you are editing your program, this is probably too much help.

### Assignment

Your assignment is to print out a table of sine values (see Sample Run below). To compute the value of sin(x) when x is an angle expressed in radians , we will use the following Taylor series:
sin(x) = x - (x^3)/3! + (x^5)/5! - (x^7)/7! + (x^9)/9! - (x^11)/11! + (x^13)/13!
To compute the value of sin(x) we will calculate only the first few terms of the infinite series. The number of terms used will be specified by the user. In the equation above, only 7 terms have been displayed. Also, in the equation above the expression 7! (read seven factorial) stands for 1 2 3 4 5 6 7. In general, n! stands for the product of 1 through n. The Taylor series we use works very well with angles expressed in radians, but most people are more familiar with angles expressed in degrees. So, the output of your program should have a table of sine values for angles between 0 and 360. To convert from degrees to radians, use the formula:
radians = PI * degrees / 180
This is enough information for you to compute the sine values for the table. You are, of course, not allowed to use the sine function in the math library. This exercise is to show you how sine values are actually computed. Finally, the format of your output should conform to the description in the sample run below -- i.e., report a sine value every 5 degrees, have three values per line, seven digits of precision and nicely formatted output. When you have determined that your program works correctly, try running the program using different numbers of terms. Check the results of your program against a calculator (be sure you have the calculator in degree mode) or a calculus textbook. You should notice that the table is more accurate when you include more terms. How many terms are needed before your program correctly determined that sin(360) is 0?

### What to turn in

When you have fully debugged your program, you will use the script command to record a sample run of your program. To do this, follow these directions carefully.
1. Check the current directory to see if there is a file called typescript. If there is a file called typescript, rename it using mv or remove it using rm. (Consult your UNIX at UMBC manual.)
2. Type script at the UNIX prompt.
3. Run your program on two test cases. For the first run, use 8 terms in the Taylor series. For the second run, use the smallest number of terms that gives you 0.0000000 for sin(360).
4. Type exit at the UNIX prompt.
After completing all 4 steps, there should be a file called typescript in your current directory. Use the cat command to display the file on the screen. If the file is empty, then you forgot to do step 4. If the output looks fine, then turn in your project using the mail2chang command (as in Project 1). When you are asked to type in the name of the output file, enter typescript for the filename. Reminder: please do not use any other program to turn in your project.

### Sample Run

The following is a sample run of one version of the project. The output from your program should be similar. For example, the output should display 3 sine values per line and give 7 digits of precision. If you are careful, the decimal points will also line up.
lassie% a.out
This program prints out a table of sine values.
The values are computed using a Taylor series.
You may specify the number terms in the Taylor series.

Enter the number of terms: 8

Table of Sines
sin(  0) =  0.0000000   sin(  5) =  0.0871557   sin( 10) =  0.1736482
sin( 15) =  0.2588190   sin( 20) =  0.3420201   sin( 25) =  0.4226183
sin( 30) =  0.5000000   sin( 35) =  0.5735764   sin( 40) =  0.6427876
sin( 45) =  0.7071068   sin( 50) =  0.7660444   sin( 55) =  0.8191520
sin( 60) =  0.8660254   sin( 65) =  0.9063078   sin( 70) =  0.9396926
sin( 75) =  0.9659258   sin( 80) =  0.9848078   sin( 85) =  0.9961947
sin( 90) =  1.0000000   sin( 95) =  0.9961947   sin(100) =  0.9848078
sin(105) =  0.9659258   sin(110) =  0.9396926   sin(115) =  0.9063078
sin(120) =  0.8660254   sin(125) =  0.8191520   sin(130) =  0.7660444
sin(135) =  0.7071068   sin(140) =  0.6427876   sin(145) =  0.5735764
sin(150) =  0.5000000   sin(155) =  0.4226182   sin(160) =  0.3420200
sin(165) =  0.2588189   sin(170) =  0.1736479   sin(175) =  0.0871553
sin(180) = -0.0000008   sin(185) = -0.0871570   sin(190) = -0.1736501
sin(195) = -0.2588220   sin(200) = -0.3420247   sin(205) = -0.4226253
sin(210) = -0.5000105   sin(215) = -0.5735921   sin(220) = -0.6428107
sin(225) = -0.7071406   sin(230) = -0.7660934   sin(235) = -0.8192225
sin(240) = -0.8661260   sin(245) = -0.9064503   sin(250) = -0.9398931
sin(255) = -0.9662059   sin(260) = -0.9851966   sin(265) = -0.9967310
sin(270) = -1.0007352   sin(275) = -0.9971967   sin(280) = -0.9861656
sin(285) = -0.9677560   sin(290) = -0.9421464   sin(295) = -0.9095809
sin(300) = -0.8703701   sin(305) = -0.8248916   sin(310) = -0.7735919
sin(315) = -0.7169875   sin(320) = -0.6556671   sin(325) = -0.5902946
sin(330) = -0.5216130   sin(335) = -0.4504494   sin(340) = -0.3777216
sin(345) = -0.3044466   sin(350) = -0.2317518   sin(355) = -0.1608878
sin(360) = -0.0932458
lassie%