Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C language The code should be work as a example in the picture above. I tried with this code, but it is not working as

C language

The code should be work as a example in the picture above.

I tried with this code, but it is not working as I thought...

Can anyone tell me what is the problem on the code?

image text in transcribed

image text in transcribed

image text in transcribed

#include

#include #include #include

long int factorial (int n);

int main() { double x; double ex; double diff;

printf ("Enter the value of x = "); scanf_s ("%1f", &x);

while (x

printf ("#iter\t e^x\t sum\t diff "); double s = 0; int i = 0;

do { printf ("%-4d", i+1);

ex = exp(x); printf ("%13.6lf", ex);

s = s+((float)pow(x,i)/(float)factorial(i)); printf ("%10.6lf", 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 Introduction Your sixth programming assignment will consist of one small C program and some written material Please note that your program should comply with the commenting and formatting rules discussed in class. For example, there should be a header for the whole program that gives the author's name, class name, date, and description. End braces should be commented, and there are alignment and indenting requirements as discussed. Please ask if you have any questions Problem #1 Taylor Series Convergence (C Program) For this program, let's calculate the Taylor series expansion for the exponential function: ex The equation we will implement is This summation will converge to ex after some number of terms have been added to the whole. The number of terms will vary depending on the value of x. Note that every term in the summation is positive, so the summation will converge to the actual value from below. "x" is assumed to be 0 In general, if we wish to test two floating point numbers for equality, we can calculate the absolute value of the difference between the numbers and then determine if that difference is less than some epsilon value Let's apply that technique to this problem. We'll test the growing sum against the standard ex value (as calculated by the exp (x) function) until the difference between the two becomes less than some epsilon (to be defined shortly). At that point we'll consider that the series has converged on the correct value. In addition, we'll track the number of terms that must be added to the sum to achieve convergence and report that value to the user. Functions Your program should contain at least two functions

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions