+ 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!

21st Apr 2019, 7:31 PM
lucianovianna
lucianovianna - avatar
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
21st Apr 2019, 9:03 PM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 2
22nd Apr 2019, 1:04 AM
lucianovianna
lucianovianna - avatar