【问题标题】:How to get the square root of a periodic decimal point number using C++? [closed]如何使用 C++ 获得周期性小数点数的平方根? [关闭]
【发布时间】:2018-09-08 04:19:58
【问题描述】:

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

示例代码:

sqrt(4/99) 

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

【问题讨论】:

  • 到底是什么问题?你能分享一些工作代码来演示它吗?
  • 这些问题时不时冒出来。但是所有这些新程序员都在使用什么学习资源呢?基本算术及其怪癖通常在 decent book 的早期介绍。
  • 如何得到周期小数点的平方根? sqrt() 方法输出为零

标签: c++ c++11


【解决方案1】:

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

【讨论】:

  • 非常感谢,它有效
猜你喜欢
  • 2020-04-25
  • 2023-03-24
  • 1970-01-01
  • 2020-01-22
  • 1970-01-01
  • 2021-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多