C++ cmath sqrt() 函数
示例
返回不同数字的平方根:
cout << sqrt(0);
cout << sqrt(1);
cout << sqrt(9);
cout << sqrt(0.64);
cout << sqrt(-25);
亲自试一试 »
定义和用法
sqrt() 函数返回一个数的平方根。
sqrt() 函数定义在 <cmath> 头文件中。
语法
以下选项之一:
sqrt(double number);
sqrt(float number);
参数值
| 参数 | 描述 |
|---|---|
| number | 必填。指定一个数字。如果该数字为整数类型,则会被视为 double 类型。 |
技术细节
| 返回值: | 表示一个数的平方根的float值(如果参数是float类型)或double值(在其他情况下)。 |
|---|

