+ 1
Taylor series- C
Can someone help me? https://i.stack.imgur.com/X3KAr.png I need to make this code work... But the fatorial wont work correctly... code: #include <stdio.h> #include <math.h> int main() { double x, z = 0, fat = 1; int n, i, j, fat2=0; scanf("%lf%d", &x, &n); j = 1; for(i = 0; i < n; i++ ) { //printf("\n%d :: %lf :: %d ", fat2, fat, i); // DEBUG z = z + ( ( pow(-1 , i)*pow(x, (2*i)) ) / (fat) ); fat2 = 2*j; fat = fat * (fat2 - i); j++; } printf("\ncos(x) = %lf\n", z); return 0; } Thanks!
2 Antworten
+ 1
you can put this on code play ground for proper editing, will look into it now
edited: a factorial function will look like this N*(N-1)
my advise for you to debug this, create a function for factorial and call it in the equation you need it
+ 2
Ty for the help.
Solved!
https://code.sololearn.com/c8sjtA4hj7DG