#include <iostream>
#include <cmath> // 包含数学函数库
using namespace std;
int main() {
double num = 16.0; // 定义一个需要开平方的数
double result = sqrt(num); // 使用sqrt函数计算开平方
cout << "The square root of " << num << " is " << result << endl; // 输出结果
return 0;
}
#include <cmath>:引入了C++标准库中的数学函数库,sqrt函数就在这个库中。double num = 16.0;:定义了一个双精度浮点数num,值为16.0,表示我们需要对16进行开平方运算。double result = sqrt(num);:调用sqrt函数对num进行开平方运算,并将结果存储在result变量中。cout语句用于输出结果到控制台。上一篇:c++ detach
下一篇:c++源码
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站