Question: This program is not giving me any values when i enter a number. For example 0.5 gives nothing but zeros. This is a Taylor Series
This program is not giving me any values when i enter a number. For example 0.5 gives nothing but zeros. This is a Taylor Series Convergence Program but no luck getting any values for e^x, the sum or the difference. Please help. #include #include #include #include long int factorial (int n); int main() { double x; double ex; double diff; printf ("Enter the value of x = "); scanf("%lf", &x); while (x < 0) { printf ("Please enter the value of x greater than 0, x = "); scanf("%lf", &x); } printf ("#iter\t e^x\t\t\t sum\t\t\t diff "); double s = 0; int i = 0; do { printf ("%-4d", i+1); ex = exp(x); printf ("%13.6lf\t\t", ex); s = s+((float)pow(x,i)/(float)factorial(i)); printf ("%10.6lf\t\t", s); diff = ex-s; printf ("%12.8lf", diff); i++; printf (" "); } while (diff > FLT_EPSILON); printf ("The number of Iterations required for convergence is : %d ",i); //system ("pause"); return 0; } long int factorial (int n) { if (n <= 1) { return(1); } else { n = n*factorial(n-1); } return(n); }
Step by Step Solution
There are 3 Steps involved in it
To troubleshoot and correct your Taylor Series Convergence Program for ex lets closely examine the implementation and identify potential points where ... View full answer
Get step-by-step solutions from verified subject matter experts
