我正在编写用于在 ada 中显示 pi 数字的 spigot 算法,但我的输出是错误的,我不知道为什么
我已经尝试弄乱我的循环范围和输出数据的不同方式,但没有正常工作
with ada.integer_text_io; use ada.integer_text_io;
with Ada.Text_IO; use Ada.Text_IO;
procedure Spigot is
n : constant Integer := 1000;
length : constant Integer := 10*n/3+1;
x,q,nines,predigit :Integer :=0;
a: array (0..length) of Integer;
begin
nines:=0;
predigit:=0;
for j in 0..length loop
a(j):=2;
end loop;
for j in 1..n loop
q:=0;
for i in reverse 1..length loop
x:=10*a(i) + q*i;
a(i):= x mod (2*i-1);
q:= x/(2*i-1);
end loop;
a(1):= q mod 10;
q:=q/10;
if q = 9 then
nines:=nines+1;
elsif q = 10 then
put(predigit+1);
for k in 0..nines loop
put("0");
end loop;
predigit:=0;
nines:=0;
else
put(predigit);
predigit:=q;
if nines/=0 then
for k in 0..nines loop
put("9");
end loop;
nines:=0;
end if;
end if;
end loop;
put(predigit);
end Spigot;
所以它应该只显示在 0 3 1 4 1 5 9 2 6 5 3 5 8 9... 但我得到的输出是 0 3 1 4 1 599 2 6 5 3 5 89... 它应该只有 1一个数字,而且 pi 的输出值也不完全正确