Computers in Engineering WWW Site - Example 12.9

Example 12.9


C Version

/*
  Program to compute a trigonometric table.
*/

#include <stdio.h>
#include <math.h>

main()
{
  /*  Declaration Statements  */
  double pi, radn, sine, cosine, angle;

  printf("C49.C -> Program to compute a trigonometric table \n");
  printf("\n");
  printf("%7s%7s%7s%7s\n", "angle", "radian", "sin", "cos");

  pi = 3.14159;

  /*  Assignment Statements  */
  angle = 0.0;                      /*  This program will produce */
  while (angle <= 45) {             /*  a trigonometric table for */
    radn = angle / 180.0 * pi;      /*  angles from 0.0 to 45.0   */
    sine = sin(radn);               /*  by step of 5 degrees.     */
    cosine = cos(radn);

    /*  Print results  */
    printf("%7.3f%7.3f%7.3f%7.3f\n", angle, radn, sine, cosine);
    angle += 5;
  }  /*  End of while{} loop  */
  printf("\f\n");

  return(0);
}
/*  End of Program C49 */
/*

Output :

C49.C -> Program to compute a trigonometric table

  angle radian    sin    cos
  0.000  0.000  0.000  1.000
  5.000  0.087  0.087  0.996
 10.000  0.175  0.174  0.985
 15.000  0.262  0.259  0.966
 20.000  0.349  0.342  0.940
 25.000  0.436  0.423  0.906
 30.000  0.524  0.500  0.866
 35.000  0.611  0.574  0.819
 40.000  0.698  0.643  0.766
 45.000  0.785  0.707  0.707

*/

Last modified: 21/07/97