C 标准库 - <math.h>

C 语言 exp() 函数用于计算 e 的 x 次方(自然指数)。

原型

double exp(double x);

exp() 是 log() 的逆运算:log(exp(x)) == x。

参数

  • x - 指数(double)。

示例

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

int main() {
    printf("exp(1) = %.5f\n", exp(1));
    printf("exp(2) = %.5f\n", exp(2));
    return 0;
}

输出:

exp(1) = 2.71828
exp(2) = 7.38906

注意事项

使用 math.h 的函数时,多数编译器需要链接数学库(编译选项 -lm,如 gcc test.c -lm -o test)。所有三角函数使用弧度制。