C program to find the value of sin(x) using the series up to the given accuracy (without using user defined function) Also print sin(x) using library function.

by Nideesh C on April 12, 2011 · 0 comments

in C Programming




/* C program to find the value of sin(x) using the series up to the given accuracy (without using user defined function) Also print sin(x) using library function. */

#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;

clrscr();

printf(“Enter the value of x (in degrees)\n”);
scanf(“%f”,&x);

x1 = x;

/* Converting degrees to radians*/

x = x*(3.142/180.0);
sinval = sin(x);

printf(“Enter the accuracy for the result\n”);
scanf(“%f”, &acc);

term = x;
sinx = term;
n = 1;

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

} while(acc <= fabs(sinval – sinx));

printf(“Sum of the sine series         = %f\n”, sinx);
printf(“Using Library function sin(%d) = %f\n”, x1,sin(x));

}         /*End of main() */

/*——————————
Output
Enter the value of x (in degrees)
30
Enter the accuracy for the result
0.000001
Sum of the sine series         = 0.500059
Using Library function sin(30) = 0.500059

RUN 2
Enter the value of x (in degrees)
45
Enter the accuracy for the result
0.0001
Sum of the sine series         = 0.707215
Using Library function sin(45) = 0.707179
———————————————*/

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. Write a C program to find the sum of ‘N’ natural numbers
  2. C program to find the sum of odd numbers and sum of even numbers from 1 to N. Output the computed sums on two different lines with suitable headings
  3. Sample – Program to find the sum of each row & column of a matrix of size n x m and if matrix is square, find the sum of the diagonals also..
  4. Sample – Program to find the sum of either of the diagonals of a 4 x 4 matrix.
  5. C program to generate and print first N FIBONACCI numbers

Leave a Comment

Previous post:

Next post: