When I try to get the square root of a periodic decimal number the result is 0
.
Example code:
sqrt(4/99)
The accuracy not important, it is okay to truncate some digits.
When I try to get the square root of a periodic decimal number the result is 0
.
Example code:
sqrt(4/99)
The accuracy not important, it is okay to truncate some digits.
You used an integer as input to the sqrt()
function.
#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