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