Using a while loop which stops due to meeting a tolerance co

Using a while loop which stops due to meeting a tolerance condition (see Lecture-Chapter 13-15, 17, the example of using a while loop for computing the Maclaurin Series for sin(x), for reference), design a function to find the following sum. sigma_n=0^infinity e^nx, x

Solution

// Efficient program to calculate e raise to the power x

#include <stdio.h>

float exponential(int n, float x)

{

    float sum = 1.0f; // initialize sum of series

    for (int i = n - 1; i > 0; --i )

        sum = 1 + x * sum / i;

    return sum;

}

// Driver program to test above function

int main()

{

    int n = 10;

    float x = 1.0f;

    printf(\"e^x = %f\", exponential(n, x));

    return 0;

}

// Efficient program to calculate e raise to the power x

#include <stdio.h>

float exponential(int n, float x)

{

    float sum = 1.0f; // initialize sum of series

    for (int i = n - 1; i > 0; --i )

        sum = 1 + x * sum / i;

    return sum;

}

// Driver program to test above function

int main()

{

    int n = 10;

    float x = 1.0f;

    printf(\"e^x = %f\", exponential(n, x));

    return 0;

}

 Using a while loop which stops due to meeting a tolerance condition (see Lecture-Chapter 13-15, 17, the example of using a while loop for computing the Maclaur
 Using a while loop which stops due to meeting a tolerance condition (see Lecture-Chapter 13-15, 17, the example of using a while loop for computing the Maclaur

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site