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 

