pascal高精度问题
答案:2 悬赏:60 手机版
解决时间 2021-01-26 01:20
- 提问者网友:欺烟
- 2021-01-25 03:28
pascal高精度问题
最佳答案
- 五星知识达人网友:雪起风沙痕
- 2021-01-25 03:53
阶乘program xiti01;
var n,i,k,j:integer;
a:array[1..1000] of integer;
begin
write('input n:');
readln(n);
a[1000]:=1;
for i:=1 to 999 do a[i]:=0;
for i:=2 to n do
begin
for j:=1000 downto 1 do a[j]:=a[j]*i;
for j:=1000 downto 1 do
begin
k:=a[j];
a[j]:=k mod 10;
a[j-1]:=a[j-1]+k div 10;
end;
end;
j:=1;
while a[j]=0 do j:=j+1;
write(n,'!=');
for i:=j to 1000 do write(a[i]);
readln;
end.第二题a/b要几百位,以下为500位program xiti02;
var a,b,c:array [0..500] of integer;
i,j,t:integer;
begin
write('input first number:');
readln(i);
write('input second number:');
readln(j);
a[0]:=i;b[0]:=i div j; c[0]:=i mod j;
write('answer:',b[0],'.');
for t:=1 to 500 do
begin
a[t]:=c[t-1]*10;
b[t]:=a[t] div j;
write(b[t]);
c[t]:=a[t] mod j;
end;
readln;
end.
第三题请说再详细点第四题program xiti04;
var b,a:array[1..1000] of integer;
i,n,t,g,f,k,j,l,h:integer;
begin
write('input n:');
readln(n);
t:=1000;
for i:=1 to 1000 do b[i]:=0;
h:=1;
a[1000]:=1;
repeat
begin
for j:=1000 downto 1 do a[j]:=a[j]*h;
for j:=1000 downto 1 do
begin
k:=a[j];
a[j]:=a[j] mod 10;
a[j-1]:=a[j-1]+k div 10;
end;
j:=1;
while a[j]=0 do j:=j+1;
if t>j then t:=j;
for f:=j to 1000 do
b[f]:=b[f]+a[f];
h:=h+1;
end;
until h-1=n;
for i:=1000 downto k do
if b[i]>9 then begin
l:=b[i];
b[i]:=l mod 10;
b[i-1]:=b[i-1]+l div 10;
end;
write('answer:');
j:=1;
while b[j]=0 do j:=j+1;
for i:=j to 1000 do
write(b[i]);
readln;
end.
var n,i,k,j:integer;
a:array[1..1000] of integer;
begin
write('input n:');
readln(n);
a[1000]:=1;
for i:=1 to 999 do a[i]:=0;
for i:=2 to n do
begin
for j:=1000 downto 1 do a[j]:=a[j]*i;
for j:=1000 downto 1 do
begin
k:=a[j];
a[j]:=k mod 10;
a[j-1]:=a[j-1]+k div 10;
end;
end;
j:=1;
while a[j]=0 do j:=j+1;
write(n,'!=');
for i:=j to 1000 do write(a[i]);
readln;
end.第二题a/b要几百位,以下为500位program xiti02;
var a,b,c:array [0..500] of integer;
i,j,t:integer;
begin
write('input first number:');
readln(i);
write('input second number:');
readln(j);
a[0]:=i;b[0]:=i div j; c[0]:=i mod j;
write('answer:',b[0],'.');
for t:=1 to 500 do
begin
a[t]:=c[t-1]*10;
b[t]:=a[t] div j;
write(b[t]);
c[t]:=a[t] mod j;
end;
readln;
end.
第三题请说再详细点第四题program xiti04;
var b,a:array[1..1000] of integer;
i,n,t,g,f,k,j,l,h:integer;
begin
write('input n:');
readln(n);
t:=1000;
for i:=1 to 1000 do b[i]:=0;
h:=1;
a[1000]:=1;
repeat
begin
for j:=1000 downto 1 do a[j]:=a[j]*h;
for j:=1000 downto 1 do
begin
k:=a[j];
a[j]:=a[j] mod 10;
a[j-1]:=a[j-1]+k div 10;
end;
j:=1;
while a[j]=0 do j:=j+1;
if t>j then t:=j;
for f:=j to 1000 do
b[f]:=b[f]+a[f];
h:=h+1;
end;
until h-1=n;
for i:=1000 downto k do
if b[i]>9 then begin
l:=b[i];
b[i]:=l mod 10;
b[i-1]:=b[i-1]+l div 10;
end;
write('answer:');
j:=1;
while b[j]=0 do j:=j+1;
for i:=j to 1000 do
write(b[i]);
readln;
end.
全部回答
- 1楼网友:山有枢
- 2021-01-25 04:41
求n!的值可以直接用一个高精度乘法就解决了吧..a/b不就是高精度除法么..n累加.. 先转换为字符串 后转换为高精度加法..如果嫌麻烦 可用公式 (n+1)*n/2 就用一个乘法和很简单的除法就可以了..阶乘和就一边调用加一边调用乘嘛..
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯