编程求出所有不超过1000的数中,含有数字3的自然数,并统计总数
pascal吧
全部回复
仅看楼主
level 7
求纠正编译错误
const n=1000;
var i,count:integer;
begin
count:=0;
for i:=1 to n do
begin
if i<10 then
begin
if i=3 then
begin
write(3,' ');
count:=count+1;
end;
end
else
begin
if (i>=10) and (i<100) then
begin
if ((i mod 10) =3) or ((i div 10) =3) then
begin
write(i,' ');
count:=count+1;
end;
end
else
begin
if (i>=100) and (i<1000) then
if (((i mod 100) mod 10) =3) or ((((i div 10) mod 10)) =3) or ((i div 100) =3) then
begin
write(i,' ');
count:=count+1;
end;
end;
end; end;
writeln();
writeln('count=',count);
readln();
end.

2012年09月01日 12点09分 1
level 12
编译通过。。。。(FP)
2012年09月01日 14点09分 2
我用的是pascal
2012年09月02日 02点09分
回复 jtl12345678910 :Free pascal编译通过,最新2.4.0的可能不稳定而[拍砖]编译失败
2012年09月02日 03点09分
level 12
program a;
const n=1000;
var i,count:integer;
begin
count:=0;
for i:=1 to n do
if (i mod 10=3)or(i div 10 mod 10=3)or(i div 100=3) then
begin
write(i,' ');
inc(count);
end;
writeln;
writeln('count=',count);
readln;
end.
2012年09月02日 03点09分 3
输出超限
2012年09月02日 04点09分
level 12
2012年09月02日 13点09分 4
在编程网上提交时说输出超限
2012年09月03日 13点09分
@jtl12345678910 我也是超出限制
2017年07月27日 09点07分
level 7
2012年09月03日 13点09分 5
level 1
#include <iostream>
using namespace std;
int main()
{
int i,j,a,b,c;
b=0;
for(i=3;i<=1000;i++)
{
if(i%10==3||(i/10)%10==3||i/100==3)
b++;
}
cout<<b<<endl;
return 0;
}
2017年08月11日 09点08分 6
1