编程求出所有不超过1000的数中,含有数字3的自然数,并统计总数。

请用pascal repeat编,谢谢repeat循环
2024-12-20 13:48:28
推荐回答(2个)
回答1:

var
i,sum:integer;
begin
sum:=0;//总个数
i:=3;
repeat
if pos('3',inttostr(i))>0 then
begin
inc(sum);
writeln(inttostr(i));
end;
inc(i);
Until i>1000;
writeln(inttostr('总数为:'sum));
end.

回答2:

var
t,i:integer;
function fj(x:integer):boolean;
var
y:integer;
begin
fj:=true;
y:=x;
while x>0 do
begin
if (y mod 10)=3 then
begin
fj:=false;
exit;
end
else y:=y div 10;
end;
end;
begin
for i:=1 to 1000 do
if fj(i) then
begin
t:=t+1;
write(i,' ');
writeln(t);
end.