#include <iostream>
#include <cmath> // 包含数学函数库
int main() {
double num = 16.0; // 定义一个需要开根号的数
double result = sqrt(num); // 使用sqrt函数计算平方根
std::cout << "The square root of " << num << " is " << result << std::endl;
return 0;
}
#include <cmath>
是为了使用数学函数库,其中包含了 sqrt
函数。double num = 16.0;
定义了一个双精度浮点数 num
,其值为 16.0。sqrt
函数:sqrt(num)
计算 num
的平方根,并将结果存储在 result
变量中。std::cout
输出计算结果。如果你有任何问题或需要进一步的帮助,请告诉我!
下一篇:菜鸟 c++
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站