-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestd.le
More file actions
48 lines (44 loc) · 1.33 KB
/
testd.le
File metadata and controls
48 lines (44 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
{Program to find square root of an integer}
{use 43 as data }
begin
write('Recommended input:'); writeln;
write('43.0'); writeln; writeln;
guess:=0.0; {first guess at answer}
inc:=1.0; {guess increment}
write('Square root.');
writeln;
write('Enter number: ');
read(n);
writeln;
if n<0.0 {No root if number is <0}
begin
write('No real root exists.');
writeln;
end
else
begin
repeat {while increment is not too small}
begin
repeat {while guess^2 is too small}
begin
guess:=guess+inc; {increase guess by increment}
end
until guess*guess >= n; {repeat}
if guess*guess=n {if guess was right}
begin {do nothing}
end
else
begin
guess:=guess-inc; {else go back to last
guess that was
smaller than right
answer}
end; {if}
inc:=inc/2.0; {halve increment then loop again}
end
until inc<0.0001; {repeat}
write('(Approximate) answer: ');
write(guess);
writeln;
end; {if}
end