Bruteforce technique to find square root of a number

https://ide.codingblocks.com/s/357296

Here is my code and I don’t want to get the precision input from user. I want to leave it on the computer. And I know this is a kind of difficult task as the precision may go endless and the program will stop working. But is there any other problem in my code other than this. I mean if it was possible that the computer will print the answer with endless precision will my program work or there are some errors in the code.

Hey @yashsharma4304
No its not correct
Because u havent initialized inc also in each iteration of loop u are decreasing inc by 10
Now assume we initialize inc =1

And we have to find sqrt(10)
now ans=0
so ans*ans<=10
we do ans+=inc=>ans=1
and inc=inc/10==>inc =0.1
Now again 1*1<=10
we do ans+=inc =>ans=1.1
now whatever u add in it its precision its always gonna be smaller than our ans and will run infinitely .

1 Like

If u want to do this even then also everything remains same except inputting p from user

Ok ok now I understand :smile:. Thank you so much.

1 Like