float cos(float p);
main()
{
float x;
printf("enter x");
scanf("%f",&x);
printf("cos(%f)=%f",x,cos(x));
}
float cos(float p)
{
float x1,sum=0,term;
int i;
x1=p*3.14159266/180;
term=1;
for(i=1; i<=20; i++)
{
sum=sum+term;
term=term*(-x1*x1)/(2*i*(2*i-1));
}
return sum;
}
Note: Need to be arranged in compiler after copied
OutPut:
enter x90
cos(90.000000)=-0.000000