But is there a actual way to do this or would i have to create my own??

Thanks but i think i'll leave that option out

You can try to bruteforce it out and just increment by 0.01 maybe that will work out.
But the answer wouldnt be exact.
So u can try in for an approx val.

Then test it up. If the value you got. is squared is lesser than the main number of which you should find the square root then increment. But if the the square of the value increases take the previous number as the approximate square root. So you will only be missing the minutest details

I've looked at websites etc, but tbh is it worth it?

I'm confused, is the sqrt function somehow deficient?

A simple method for calculating square root of a number "a" is given by newton iteration as

``````for(int i=0;i<10;i++)
{
xn=.5*(x0+(a/x0));
x0=xn;
}``````

where x0 is initialized to 1. Use float comparisons and loop till xn equals x0 here I have used a loop for simplicity. Again why cant you use sqrt()?

I never said i cant use sqrt() i just said i dont know if it's worth it

A simple method for calculating square root of a number "a" is given by newton iteration as

``````for(int i=0;i<10;i++)
{
xn=.5*(x0+(a/x0));
x0=xn;
}``````

where x0 is initialized to 1. Use float comparisons and loop till xn equals x0 here I have used a loop for simplicity. Again why cant you use sqrt()?

Sorry I forgot to mention that xn will give you the square root. You can initialize to any other number also.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.