温馨提示×

如何在C++中使用数学库计算ln函数

c++
小樊
100
2024-08-18 07:58:34
栏目: 编程语言

在C++中,可以使用<cmath>头文件中的log()函数来计算ln函数。例如:

#include <iostream>
#include <cmath>

int main() {
    double x = 10.0; // 输入要计算ln的数值
    double result = log(x); // 计算ln(x)
    
    std::cout << "ln(" << x << ") = " << result << std::endl;
    
    return 0;
}

上面的代码示例中,我们使用log()函数来计算ln(10)的值,并将结果打印出来。更多关于cmath头文件中数学函数的使用,可以查阅C++的相关文档。

0