Hi , I've been cracking my head with this Taylor's series problem , im new in c++ and need some help with my code , the output of both sine and cosine is 0 and 1 respectevely . So far I understand that the signs alternate but im not sure if my way of doing it is the correct one. Thanks in advance for your help .
float factorial(int w)
{
int y=1,z;
z=w;
int n =1;
while (n<=z){
y*=n;
n++;
}
return y ;
}
float sine( float x){
int fact;
for ( int j =0;j<100;j++){
for ( int i =1;i<10; i++){ {
if ( i%2!=0){
fact=factorial(i);
x+= (j%2==0 )? ((-(pow (x,i)))/fact) :((pow (x,i))/fact );//
}
}
return x;
}
Why do you have two for loops? Seems like for the Taylor series you only need one. Also, line 39 shouldn't be x... x should be the angle provided (the angle you want the sine or cosine of).