扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

c++中exp函数的用法是什么

扬州沐宇科技
2024-03-12 18:18:40
c++

在C++中,exp函数用于计算 e 的 x 次方,其中 e 是自然对数的底数,x 是函数的参数。exp函数的原型如下:

double exp(double x);

其中,参数 x 是一个双精度浮点数,表示要计算 e 的 x 次方的指数。

示例:

#include <iostream>
#include <cmath>

int main() {
    double x = 2.0;
    double result = exp(x);
    std::cout << "e raised to the power of " << x << " is " << result << std::endl;
    return 0;
}

在上面的示例中,我们使用exp函数计算 e 的 2 次方,并打印出结果。输出应该为:

e raised to the power of 2 is 7.38906

扫码添加客服微信