2) The program calculates cosines values for angle 0,10,20.......180 and prints out the results with headings.

#include <math.h>
#define    PI3.1416
#define    MAX 180

main( )
 {
        int angle;
        float x,y;
      
        angle = 0;
        printf(" Angle    Cos(angle)\n\n);
        
        while(angle <= MAX)
         {
                 x = (PI/MAX)*angle;
                 y = cos(x);
                 printf("%15d %13.4f\n", angle, y);
                 angle = angle + 10;
         }
       getch();
 } 

Output: Angle         Cos(angle)
                   0                 1.0000
                   10               0.9848
                   20               0.9397
                   30               0.8660
                   40               0.7660
                   50               0.6428
                   60               0.5000
                   70               0.3420
                   80               0.1736
                   90              -0.0000
                  100             -0.1737
                  110             -0.3420
                  120             -0.5000
                  130             -0.6428
                  140             -0.7660
                  150             -0.8660
                  160             -0.9397
                  170             -0.9848
                  180             -1.0000

                         Program using a math function
  

No comments:

Post a Comment