Sunday, 23 February 2014

find the value of cosx

find the value of cosx
#include<stdio.h>
int main()
{
int n,x1;
float acc,term,den,x,cosx=0,cosval;
printf("Enter the value of  x (in degrees)\n");
scanf("%f",&x);
x1=x;
//converting degrees to radians
x=x*(3.142/180.0);
cosval=cos(x);
printf("Enter the accuay  for the result \n");
scanf("%f",&acc);
term=1;
cosx=term;
n=1;
do
{
    den=2*n*(2*n-1);
    term=-term*x*x/den;
    cosx=cosx+term;
    n=n+1;
}
while(acc<=fabs(cosval-cosx));
printf("sum of cosine series=%f\n",cosx);
printf("using library fuction cos(%d)=%d\n",x1,cos(x));
    return 0;

}

No comments:

Post a Comment