You are on page 1of 8

C PROGRAMMING LABORATORY

18CPL17/27
Program 9
Develop a Program to compute Sin(x) using
Taylor series approximation. Compare your
result with the built- in Library function. Print
both the results with appropriate messages.
Taylor Series
Program 9
#include<stdio.h>
#define PI 3.142
void main( )
{
int i, degree;
float x, sum=0, term, num, deno;
printf(“Enter the value in degrees:\n”);
scanf(“%d”, &degree);
x=degree * (PI / 180);
num= x;
deno=1;
i = 2;
Program 9
do
{
term = num/deno;
num = -num*x*x;
sum = sum+term;
deno = deno*i*(i+1);
i = i + 2;
} while(fabs(term)>=0.00001);
Program 9
printf(“The sine of %d is: %f\n”, degree, sum);
printf(“The sine function of %d is: %f\n” ,
degree, sin(x));

}
Program 9
Output:
1. Enter the values in degrees:90
The sine of 90 is 1.000000
The sin function of 90 is 1.000000

2. Enter the values in degrees:45


The sine of 45 is 0.706825
The sin function of 45 is 0.706825

You might also like