作业帮 > 综合 > 作业

求高精度幂Description 对数值很大、精度很高的数进行高精度计算是一类十分常见的问题.比如,对国债进行计算就是属

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/28 19:25:27
求高精度幂
Description
对数值很大、精度很高的数进行高精度计算是一类十分常见的问题.比如,对国债进行计算就是属于这类问题.
现在要你解决的问题是:对一个实数R( 0.0 < R < 99.999 ),要求写程序精确计算 R 的 n 次方(Rn),其中n 是整数并且 0
var st,a,b:string; e,i,z:longint; code:integer;
function cheng(a,b:string):string;
var c,x,y:array[0..480]of longint;
l,i,m,j:longint; s:string;
begin
if (a='0')or(b='0')
then begin cheng:='0'; exit; end;
fillchar(c,sizeof(c),0);
fillchar(x,sizeof(x),0);
fillchar(y,sizeof(y),0);
l:=length(a);
for i:=1 to l do
x[i]:=ord(a[i])-48;
m:=length(b);
for i:=1 to m do
y[i]:=ord(b[i])-48;
for i:=m downto 1 do
for j:=l downto 1 do
c[j+i-1]:=c[j+i-1]+y[i]*x[j];
for i:=m+l-1 downto 1 do
if c[i]>=10
then begin c[i-1]:=c[i-1]+c[i] div 10; c[i]:=c[i] mod 10; end;
s:='';
if c[0]0 then s:=chr(c[0]+48);
for i:=1 to l+m-1 do s:=s+chr(c[i]+48);
cheng:=s;
end;
begin
while not eof do
begin
readln(st);
val(copy(st,8,2),e,code);
a:=copy(st,1,6);
b:=a;
z:=length(b)-pos('.',b);
delete(b,pos('.',b),1);
while (b[1]='0')and(length(b)>1) do delete(b,1,1);
for i:=2 to e do
begin
delete(a,pos('.',a),1);
while (a[1]='0')and(length(a)>1) do delete(a,1,1);
a:=cheng(a,b);
while length(a)