smithsps
2008-05-22 21:17:21
I made this script for a Quadratic Equation Solver that does not use decimal approximation. Hope anyone can use this.
Comments Please!
\\\**Returns as 'Sqrt(Num)' if it cannot work**///
***Function***
***Working Script***
Comments Please!
\\\**Returns as 'Sqrt(Num)' if it cannot work**///
***Function***
function SquareRootSymbol(Num: integer) : string;
var
Check : integer;
Stop : boolean;
begin
repeat
Inc(Check);
if((Check * Check) = Num)then Result := IntToStr(Check);
if((Check * Check) > Num)then Stop := True;
until(Result = IntToStr(Check)) or (Stop = True);
if(Stop)then
begin
Check := Num;
repeat
Dec(Check);
if(Num - ((Num div (Check * Check)) * (Check * Check)) = 0)then Break;
until(Check = 0);
end;
if(Check < 2)then
Result := 'Sqrt('+ IntToStr(Num) + ')';
if(Stop) and (Check > 2)then
Result := IntToStr(Check) + ' Sqrt(' + IntToStr(Num div (Check * Check)) + ')';
end;***Working Script***
program SqrtS;
function SquareRootSymbol(Num: integer) : string;
var
Check : integer;
Stop : boolean;
begin
repeat
Inc(Check);
if((Check * Check) = Num)then Result := IntToStr(Check);
if((Check * Check) > Num)then Stop := True;
until(Result = IntToStr(Check)) or (Stop = True);
if(Stop)then
begin
Check := Num;
repeat
Dec(Check);
if(Num - ((Num div (Check * Check)) * (Check * Check)) = 0)then Break;
until(Check = 0);
end;
if(Check < 2)then
Result := 'Sqrt('+ IntToStr(Num) + ')';
if(Stop) and (Check > 2)then
Result := IntToStr(Check) + ' Sqrt(' + IntToStr(Num div (Check * Check)) + ')';
end;
begin
ClearDebug;
writeln(SquareRootSymbol(45));
end.