#include <iostream>
#include <cmath> // 包含数学函数库
int main() {
double number = 25.0; // 定义一个需要求平方根的数
double result = sqrt(number); // 使用sqrt函数求平方根
std::cout << "The square root of " << number << " is " << result << std::endl;
return 0;
}
sqrt 函数就定义在这个库中。number,并赋值为25.0。sqrt 函数计算 number 的平方根,并将结果存储在 result 变量中。这段代码展示了如何在C++中使用 sqrt 函数来计算一个数的平方根。
上一篇:c++ 静态类
下一篇:c++泛型
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站