I am working on a problem involving Taylor's Series of cosine x and sine x. (cosx = 1 - (x^2/2!) + (x^4/4!) - ...)
My only problem is how I can do the alternating plus minus on each term. This is the code I currently have in which I can't still figure out if it is right or wrong.
double cosine(double x)
int n, ctr;
cos = 0;
n = 2*NUMBER_OF_TERMS;
ctr = NUMBER_OF_TERMS;
while(ctr > 0)
cos = cos + (RaiseTo(x, n)/factorial(n));
cos *= -1;
n -= 2;
*Note: We were only allowed to use stdio.h as the header file.