Board index » delphi » Square Root program needed

Square Root program needed

if anyone has a pascal program that does square roots please send..
thanks
dan
 

Re:Square Root program needed


Quote
Danny wrote:

> if anyone has a pascal program that does square roots please send..
> thanks
> dan

------------------------------- cut here ----------------------------

var num:integer;

function squareroot(num:real):real;
var i:integer;
    ans:real;
begin
    ans:=1.0;
    for i:=1 to 10 do
        ans:=ans-(ans*ans-num)/(2*ans);
    squareroot:=ans;
end;

begin
     writeln('enter a number ');
     readln(num);
     writeln('squareroot(',num,')=',squareroot(num):0:18);
end.

-------------------------- cut here --------------------------

--
  Eric
----------------------------------------------
Sex without love is an empty experience.
But as empty experiences go, it's one of the best.
        --Woody Allen

Re:Square Root program needed


On Sun, 13 Sep 1998 20:30:17 -0400, "Danny" <air...@mindspring.com>
wrote:

Quote
>if anyone has a pascal program that does square roots please send..

begin
  writeln(sqrt(2))
end.

Regards
Horst

Re:Square Root program needed


In article <35fcad30.1135443...@news.snafu.de>, Horst Kraemer
<horst.krae...@snafu.de> writes

Quote
>On Sun, 13 Sep 1998 20:30:17 -0400, "Danny" <air...@mindspring.com>
>wrote:

>>if anyone has a pascal program that does square roots please send..

>begin
>  writeln(sqrt(2))
>end.

A small check on whether the number is negative might be worthwhile?
That only makes it a bit more complex I imagine.

:-)

--
Oz

Re:Square Root program needed


Quote
Oz wrote:

> In article <35fcad30.1135443...@news.snafu.de>, Horst Kraemer
> <horst.krae...@snafu.de> writes
> >On Sun, 13 Sep 1998 20:30:17 -0400, "Danny" <air...@mindspring.com>
> >wrote:

> >>if anyone has a pascal program that does square roots please send..

> >begin
> >  writeln(sqrt(2))
> >end.

> A small check on whether the number is negative might be worthwhile?
> That only makes it a bit more complex I imagine.

> :-)

> --
> Oz

In this case it's hardly necessary. By my knowledge 2 is not negative
until proven otherwise.

;-)

Remco

Re:Square Root program needed


In article <35FD21CB.8A5D3...@xs4all.nl>, Remco de Korte
<remco...@xs4all.nl> writes

Quote
>In this case it's hardly necessary. By my knowledge 2 is not negative
>until proven otherwise.

>;-)

Yes, but it's NEARLY negative .....  :-)

--
Oz

Re:Square Root program needed


JRS:  In article <6thnnt$o3...@camel15.mindspring.com> of Sun, 13 Sep
1998 20:30:17 in comp.lang.pascal.borland, Danny <air...@mindspring.com>
wrote:

Quote
>if anyone has a pascal program that does square roots please send..
>thanks
>dan

An ill-phrased question.  

My  http://www.merlyn.demon.co.uk/programs/longcalc.pas  can do square-
roots, of integers up to a thousand or more digits (bases 2..16) - but
it is 1416 lines, and I don't want to pay to upload it when you can
fetch it from that URL - and perhaps you don't want 1416 lines.

--
John Stockton, Surrey, UK.    j...@merlyn.demon.co.uk    Turnpike v1.12    MIME.
  Web <URL: http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
  Correct 4-line sig. separator is as above, a line precisely "-- " (SoRFC1036)
  Do not Mail News to me.    Before a reply, quote with ">" or "> " (SoRFC1036)

Re:Square Root program needed


Quote
>>In this case it's hardly necessary. By my knowledge 2 is not negative
>>until proven otherwise.

>>;-)

>Yes, but it's NEARLY negative .....  :-)

>--

i^2 = -1
SQRT(-1) = i;

uhh... a little to COMPLEX :))

Telemachos

Other Threads