smithsps
2008-05-22 21:37:30
What is the best Function/Procedure you ever made?
Well if you have one then post it!
*You may post more than one.*
Here is mine:
Well if you have one then post it!
*You may post more than one.*
Here is mine:
function SquareRootSymbol(Num: integer) : string;
var
Temp, ModCheck : integer;
Stop : boolean;
begin
Inc(Temp);
repeat
if((Temp * Temp) = Num)then Result := IntToStr(Temp);
if((Temp * Temp) < Num)then Inc(Temp);
if((Temp * Temp) > Num)then Stop := True;
until(Result = IntToStr(Temp)) or (Stop = True);
if(Stop = True)then
begin
ModCheck := Num;
repeat
Dec(ModCheck);
Temp := ModCheck * ModCheck;
if(Num - ((Num div Temp) * Temp) = 0)then Break;
until(ModCheck = Num);
end;
if(ModCheck = Num) and (Stop = True)then
begin
Result := '0';
writeln('Can''t compute, in other words, WONT WORK');
writeln('Sqrt(' + IntToStr(ModCheck) + ')');
end;
if(Stop) and (ModCheck <> Num)then
begin
Temp := Num div (ModCheck * ModCheck);
writeln('Square Root = ' +IntToStr(ModCheck) + ' Sqrt(' + IntToStr(Temp) + ')');
Result := IntToStr(ModCheck) + ' Sqrt( ' + IntToStr(Temp) + ' )';
end;
if not(Stop)then
writeln('Square Root = ' + Result);
end;