新闻资讯

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻资讯列表

C++ cmath库如何计算平方根,c++ cmath math.h

发布时间:2024-07-09 03:14:22

C++ cmath库如何计算平方根

C++的cmath库中提供了sqrt()函数来计算平方根。下面是一个示例代码:

#include <iostream>
#include <cmath>

int main() {
    double num = 64.0;
    double result = sqrt(num);

    std::cout << "Square root of " << num << " is " << result << std::endl;

    return 0;
}

在上面的代码中,我们包括了cmath头文件,并使用sqrt()函数计算了64的平方根。输出将会是:

Square root of 64 is 8

tiktok粉丝购买:https://www.smmfensi.com/