Sunday, January 27, 2008

PROGRAM TO CALCULATE SQUARE ROOT OF A NUMBER

Algorithm:

read(n);
Step1:Take a initial guess guess1=some arbitary value (close to the number);
Step 2:Divide the number n by initial guess and store it in a variable g =n/guess1;
Step 3: Take the average of guess1 and g and store if guess2 ,guess2 = (guess1+g)/2;

repeat the process untill guess2 is less than guess1

while(guess2 {
guess1=guess2;
g=n/guess1;
guess2=(guess1+g)/2;
}

print(guess2);

1 comment:

Anonymous said...

Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Celular, I hope you enjoy. The address is http://telefone-celular-brasil.blogspot.com. A hug.