Sunday, 15 March 2015

Program to calculate the sine series Using C

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

void main()
{
int i, n ;
float x, val, sum, t ;
clrscr() ;
printf("Enter the value for x : ") ;
scanf("%f", &x) ;
printf("\nEnter the value for n : ") ;
scanf("%d", &n) ;
val = x ;
x = x * 3.14159 / 180 ;
t = x ;
sum = x ;
for(i = 1 ; i < n + 1 ; i++)
{
t = (t * pow((double) (-1), (double) (2 * i - 1)) *
x * x) / (2 * i * (2 * i + 1)) ;
sum = sum + t ;
}
printf("\nSine value of %f is : %8.4f", val, sum) ;
getch() ;
}

RUN 1 :
~~~~~~~
Enter the value for x : 30
Enter the value for n : 20
Sine value of 30.000000 is : 0.5000

No comments:

Post a Comment