0% found this document useful (0 votes)
39 views1 page

Algorithm Enthusiasts' Guide

This program calculates the square root of a user-input number (a) using the Babylonian method. It initializes variables x and y, sets x to 1, calculates y as the average of x and a/x, updates x to be y, recalculates y as the average of the new x and a/x, and repeats until the values converge to the square root. It then displays the final value of y, which approximates the square root of a.

Uploaded by

AliOuchar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views1 page

Algorithm Enthusiasts' Guide

This program calculates the square root of a user-input number (a) using the Babylonian method. It initializes variables x and y, sets x to 1, calculates y as the average of x and a/x, updates x to be y, recalculates y as the average of the new x and a/x, and repeats until the values converge to the square root. It then displays the final value of y, which approximates the square root of a.

Uploaded by

AliOuchar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Program sqroot

VAR

a,x,y :real

Writeln(give a)

Readln(a)

x=1

y=0.5(x+a/x)

x=y

y=0.5(x+a/x)
end while
writeln(y)

var
i : Integer;
a, r0, r1 : Integer;
begin
r0 := x2-x1;
r1 := y2-y1;
a := r0*r0 + r1*r1;
r1 := (1+a) DIV 2;
FOR i := 1 TO 12 DO
begin
r0 := r1;
IF r0 > 0 then r1 := (r0+(a div r0)) div 2;
end;
Result:= r1;
end;

You might also like