如何使用C++获取周期性小数点的平方根?

-9 c++ c++11

当我试图获得周期性十进制数的平方根时,结果是0.

示例代码:

sqrt(4/99) 
Run Code Online (Sandbox Code Playgroud)

准确性不重要,可以截断一些数字.

sch*_*_76 8

您使用整数作为sqrt()函数的输入.

#include <cmath>
#include <iostream>

int main(int argc, char** argv)
{
    std::cout << std::sqrt(4 / 99) << std::endl;
    std::cout << std::sqrt(4.0 / 99) << std::endl;
}

Output
0
0.201008
Run Code Online (Sandbox Code Playgroud)