我需要计算大数字的平方根(最多10 ^ 100)和设置的精确度(浮点后最多50个符号)。为了这个目标,我很想使用Digit-by-digit calculation method。但是当我在Delphi 7上实现它时,我遇到了很多麻烦并且在我的代码中感到困惑。你能说明你将如何实现这项任务。谢谢 这是我的代码
program sqrtCalc;
{$APPTYPE CONSOLE}
{$Q+} {$R+}
uses
SysUtils,math;
const
signCount=50;
var
inputString:String;
root:String;
intString,realString:String;
intArray,realArray:array of Integer;
intRootArray,realRootArray:Integer;
i,j,dotPosition:Integer;
a,b,c,d:Integer;
Procedure input();
begin
WriteLn('x=');
try
readln(inputString)
except
Writeln('Invalid input data, please try again');
input();
end;
end;
begin
input();
dotPosition:=pos('.',inputString);
if dotPosition<>0 then
begin
realString:=copy(inputString,dotPosition+1,Length(inputString)-1);
intString:=copy(inputString,0,dotPosition-1);
if odd(Length(realString)) then Insert('0',realString,Length(realString)+1);
i:=1;
while i<Length(realString) do
begin
SetLength(realArray,length(realArray)+1);
realArray[length(realArray)-1]:=StrToInt(copy(realString,i,2));
i:=i+2;
end;
end
else
intString:=inputString;
if odd(Length(intString)) then Insert('0',intString,1);
i:=1;
while i<Length(intString) do
begin
SetLength(intArray,length(intArray)+1);
intArray[length(intArray)-1]:=StrToInt(copy(intString,i,2));
i:=i+2;
end;
//Here must be implementation of mathematic actions
//But i got confused
a:=trunc(sqrt(intArray[0])); root:=IntToStr(a);
b:=intArray[0]-a*a;
c:=StrToInt(root)*20;
d:=
Write(b);
Readln;
end.