c++

C++中math库的用法是什么

小亿
93
2024-06-04 09:26:22
栏目: 编程语言

C++中的math库提供了一些数学函数和常量,可以用来进行数学运算和计算。使用math库需要包含头文件

以下是一些常用的math库函数和常量:

  1. 数学函数:
  1. 常量:

示例代码:

#include <iostream>
#include <cmath>

int main() {
    double x = 2.5;
    
    std::cout << "Square root of " << x << " is " << sqrt(x) << std::endl;
    std::cout << "2 to the power of 3 is " << pow(2, 3) << std::endl;
    std::cout << "sin(PI/2) is " << sin(M_PI/2) << std::endl;
    
    return 0;
}

以上是math库的基本使用方法,更多详细的函数和常量可以查阅C++标准库的文档。

0
看了该问题的人还看了