With a C program Calculate the value of sinx up to the given accuracy

sine is the trigonometric function of a angle of a right triangle. for a angle sine value is defined as ratio of length of the side opposite that angle to the length of the hypotenuse of the triangle [ means the longest side of the triangle ]

Normally all trigonometric functions defined as ratio of sides of the triangle which have a angle too.   The sine values for the defined angles are sine 0 = 0, sine 90 = 1, sine 30 = .5 etc

Here this C program we find out the value of sine x up to the given accuracy. For that firstly we are converting the given degrees to radians. the we are using a do while loop where we use the steps given below.

         den = 2*n*(2*n+1);
term = -term * x * x / den;
sinx = sinx + term;
n = n + 1;

this c program we use do while loop where the condition is checked after the first iteration, so loop will execute at-least one time for sure. finally we display the output.

#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
void main()
  int n, x1;
  float  acc, term, den, x, sinx=0, 
sinval;    /* declares acc, term, den, sinx, sinval as float */
  printf("Enter the value of x (in degrees)\n");    /* gets the value of x in degrees */
  x1 = x;
  /* Converting degrees to radians*/
  x = x*(3.142/180.0);
  sinval = sin(x);
  printf("Enter the accuracy for the result\n");        /* receives value of accuracy */
  scanf("%f", &acc);
  term = x;
  sinx = term;
  n = 1;
	 den = 2*n*(2*n+1);
	 term = -term * x * x / den;                  /* enters do while loop and use the formula to find den */
	 sinx = sinx + term;                          /* find term using -term*x*x/den */
	 n = n + 1;
 while(acc <= fabs(sinval - sinx));                  /* while condition checking */
  printf("Sum of the sine series         = %f\n", sinx);
  printf("Using Library function sin(%d) = %f\n", x1,sin(x));  /* prints the value of sinx */
}         /*End of main() */
OUTPUT of C program to find the value of sinx up to accuracy
Enter the value of x (in degrees)
Enter the accuary for the result
Sum of the sine series = 0.500059
Using Library function sin(30) = 0.500059

Enter the value of x (in degrees)
Enter the accuary for the result
Sum of the sine series = 0.707215
Using Library function sin(45) = 0.707179