I am trying to calculate the square root, and keep the part which could not change into integer in C++, and I found This post on Stack Overflow, but it will still have decimal.
For example, if I want to calculate √8
, I want the result to be 2√2
but not 2.828
. I also found This post, but it will only determine if its an integer, but not solving it.
At first, I tried to keep each number that could not be changed into integer completely, and using while loop to achieve that, but I found that it is almost impossible to do that, because there are too many numbers(2,3,5,7,10,13,17,19,23,27...). When I typing √573818832
into Microsoft Math Solver, it could show me that the number is equal to 12√3984853
, and I wonder how could it solve the problem.
Is there are any ways to improve my first method?