c++

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

小亿
135
2024-06-04 09:26:22
栏目: 编程语言
C++开发者专用服务器,限时0元免费领! 查看>>

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++标准库的文档。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

相关推荐:C++中math库的优缺点是什么

0
看了该问题的人还看了