我在 PAscal 中遇到问题。我想计算素数但没有结果:我的代码是:
Program arrayToFunction;
const
size = 5;
type
a = array [1..size] of integer;
var
aNumbers: a = (1, 7, 3, 4, 5);
iCountNumbers: integer;
function countPrimeNumbers( var arr: a) : integer;
var
i :0..size;
sum,j,count: integer;
begin
sum := 0;count:=0;
for i := 0 to size do
begin
for j := 2 to arr[i] do
begin
if(arr[i] mod j = 0) then sum:=1;
end;
if(sum=0) then count:=count+1;
end;
countPrimeNumbers := count;
end;
begin
iCountNumbers := countPrimeNumbers( aNumbers ) ;*)
writeln( 'Numbers: ', iCountNumbers);
readln;
end.
对于这个数组,我想得到 3,但我得到 2……我不明白我的问题出在哪里。请帮帮我