如何使用C 获取周期十进加点号的平方根

How to get the square root of a periodic decimal point number using C++?

本文关键字:平方根 何使用 获取 周期      更新时间:2023-10-16

当我尝试获得周期十进制数字的平方根时,结果为 0

示例代码:

sqrt(4/99) 

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

您使用整数作为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