Hey i've made a simple calculator, but i was thinking about adding a square root option..

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

PLEASE REPLY A.S.A.P

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

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()?

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.

This article has been dead for over six months. Start a new discussion instead.