Please Help! The function ex can be expressed as an infinite power series as fol
ID: 3545519 • Letter: P
Question
Please Help!
The function ex can be expressed as an infinite power series as follows: ex = 1+x/1! + x2/2! + x3/3! + x4/4!+... Or as a general term: Program requirements: Use a main program and two user-defined Function subprograms. In the main program, prompt the user to enter a value, x, to use in calculating ex. In the main program, prompt the user to enter a maximum value of the last term in the series (suggested value = 1 times 10-7). In the main program, output the answer (the calculated ex value) Use a user-defined Function to calculate the exponential (ex) function. Use a user-define Function to calculate a Factorial, N!Explanation / Answer
#include <math.h>int main(void)
{
double y;
double x=2.37;
y = exp(x);
printf("%f ",y);
getc(stdin);
return 0;
} double myexp(double x);
int main ()
{
double x;
printf("Enter x: ");
scanf("%d", &x);
printf("exp(%d) = ", x, myexp(x));
return 0;
}
double myexp(double x)
{
double x;
double term = 1.0; //represents a term in exponential series
double sum = 0; //represents an approximation to e^x
int n = 1; //counter LCV
while (n <= x) {
sum += term;
term = term * x / n;
n += 1;
if (term < EPSILON)
break;
else
sum += term;
}
return; //return value
double myexp(double x);
int main ()
{
double x;
printf("Enter x: ");
scanf("%d", &x);
printf("exp(%d) = ", x, myexp(x));
return 0;
}
double myexp(double x)
{
double x;
double term = 1.0; //represents a term in exponential series
double sum = 0; //represents an approximation to e^x
int n = 1; //counter LCV
while (n <= x) {
sum += term;
term = term * x / n;
n += 1;
if (term < EPSILON)
break;
else
sum += term;
}
return; //return value