Write a C program to compute the value of the mathematical constant e to the power of x (ex) using the following infinite series: e* = 1 + x/1! + x2/2! + x3/3! + x4/4! + . Your program should include at least one function called compute_ex that receives any value of x as a parameter and returns the value of ex for the given value x. The computation should stop when the new term added (term = xw/n! where n=0,1,2,3,…) is less than 0.0001 Your program should also NOT use the already predefined system function pow. Items that should be submitted: 1. The C-program (main.c). 2. A softcopy of one program run showing the value your program calculates for ex in a word document. Example of a Sample Run: Enter the value of x: 2.5 e to the power 2.5 = 12.18

95 1

Get full Expert solution in seconds

$1.97 ONLY

EXPERT ANSWER

#include <stdio.h>

int main()
{
int n = 10;
printf(“Enter the value of x”);
float x = scanf(“%f”,&x);
printf(“e^x = %f”, compute_ex(n, x));
return 0;
}

float compute_ex(int n, float x)
{

//The function potentially has a singular point at zero as 𝑒0=1

float sum = 1.0; // initialize sum of series


for (int i = n – 1; i > 0; –i ) // calculating sum using this loop
sum = 1 + x * sum / i;

return sum;
}