Write the behavior of a C function with the prototype below
Write the behavior of a C function with the prototype below. Do not use any C library functions. In case it\'s not clear, this function should calculate e^x. Repeat the previous question using the exp() function from the math. h library. Note that you are just replacing the internals of the function you wrote in Question 2.
Solution
//Solution of Question 2
#include <stdio.h>
//Return the value of EtoTheX
float EtoTheX(int n, float x)
{
// Declare and initialize the local variable
float sum = 1.0f;
for (int j = n - 1; j > 0; --j )
sum = 1 + x * sum / j;
return sum;
}
// Test the above function
int main()
{
int n = 5;
float x = 1.0f;
printf(\"EtoTheX = %f\", EtoTheX(n, x));
return 0;
}
//Solution of Question 2
#include <stdio.h>
#include <math.h>
float EtoTheX(int n, float x)
{
float sum = 1.0f;
sum=expf(x);
return sum;
}
