I'm working at something easy...I guess, but there is something that bothers me.
double x,t,cos_aprox,eps;
int k;
t=1.0;
k=1;
cos_aprox=1.0;`
printf("Introduceti x pentru care se calculeaza cos(x) si eroarea epsilon:\n");
if(scanf("%lf%lf",&x,&eps)!=2)
{
printf("Date eronate!!\n");
exit(1);
}
else
{
do
{
t=t*(-1)*x*x/(k*(k+1));
cos_aprox+=t;
k+=2;
}
while(fabs(t)>eps);
printf("Valoarea aproximativa a lui cos(%g) este %.9g. k este %d\n",x,cos_aprox,k);
printf("Valoarea lui cos(%g), folosind functia din biblioteca, este %.9g.",x,cos(x));
}
It returns good results but when I choose any value over 39 radians there is a significant difference between it and library function cos(x)
.