/* Week 3 code sample for CPS125. Ferworn Fall 06
Accessing Mathematical Functions

C gives you some basic math operators (/*+-%) but you have
access to a wide variety of complex mathematical functions.
The functions mostly live in the library "math.h". Below you will
find some example of using some functions.
*/

#include <stdio.h>
#include <math.h>
#define PI 3.14159

/* compute a table of the sin, cos and tan function for angles between 0 and 360 degrees
in 10 degree increments.*/
int main()
{
	/* define a file that we can write this stuff to */
	FILE *outfile;
    int    angle_degree;
    double angle_radian, svalue, cvalue, tvalue;

	outfile = fopen("trigvalues.txt", "w");

	/* Print a header */
    fprintf (outfile,"\nCompute a table of the sine function\n\n");

    fprintf (outfile, " angle\tSin\t\tCos\t\tTan \n" );

    angle_degree=0;			/* initial angle value 		 */

    while (angle_degree <= 360)	 /* loop until angle_degree > 360 */
    {
       angle_radian = PI * angle_degree/180.0 ; /* convert to radians...why? */
       svalue = sin(angle_radian);
	   cvalue = cos(angle_radian);
	   tvalue = tan(angle_radian); /* what is wrong with this */
	   
       fprintf (outfile, " %3d\t%f\t%f\t%f \n ", angle_degree, svalue, cvalue, tvalue );

       angle_degree = angle_degree + 10; /* increment the loop index by 10	   */
    }
	fclose(outfile);
}