C Language | Trigonometric Function SINE

Wednesday, 19 December 2012

Trigonometry is the study of any triangles. In this, trigonometric functions are present to help us calculate anything from missing areas to missing sides to elevations. There are six (6) Trigonometric Functions namely sine, cosine, tangent, cotangent, secant and cosecant.

In connection to trigonometric functions I made a program that shows you how it works. This program shows you how to calculate for the sine function equivalent of any triangle. This program is used with the header file math.h to allow mathematical commands inside the program. Check out the sample codes below.


     1: #include <stdio.h>
   2:  #include <conio.h>
   3:  #include <math.h>
   4:  # define pi 3.14159265
   5:   
   6:   
   7:  int main()
   8:  {
   9:            int angleA;
  10:            
  11:            printf ("Enter angle: ");
  12:            scanf("%d", &angleA);
  13:            
  14:            float sineA = sin(angleA*pi/180);
  15:            
  16:            printf("sine: %.2f ",sineA);
  17:            
  18:            getch();
  19:            }


The program operates like this. As seen above, we define the PI (3.14159265) as a global variable to make it more easier to use anywhere in the program. When run, it will ask the user to input any angle value. After that, the input will be stored in the variable angleA. The program will then execute the equation of the sine function (shown above) to get the equivalent value for the entered angle value. Then the program will print out the result and terminates the program. You can check out the sample output below.


Hope you learned something from this program. Thanks!

No comments:

Post a Comment

Please do leave a comment. It's gonna be a friendly conversation between programmers. Hope you do find our blog helpful. Thank you!

Related Posts Plugin for WordPress, Blogger...