How is the “exp” function used in the C language?

In the C language, the exp function is used to calculate the power of the natural logarithm base e. Its declaration is as follows:

double exp(double x);

In this case, x is the specified exponent. The exp function returns the value of e raised to the power of x.

Here is a sample code demonstrating how to use the exponential function.

#include <stdio.h>
#include <math.h>

int main() {
    double x = 2.0;
    double result = exp(x);
    
    printf("e raised to the power of %f is %f\n", x, result);
    
    return 0;
}

In the example above, we included the math.h header file, then used the exp function to calculate the power of e to the 2nd degree, and printed the result. Running the program will output:

e raised to the power of 2.000000 is 7.389056
Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds