In the following code, I want to replace the termination condition to: if the ratio of guess square and x is close to 1, while loop should terminate. I tried various express
if the ratio of guess square and x is close to 1
Then why are you subtracting? Use ratio operator:
while(absolute( (guess*guess) / x - 1) >= 0.0001 )