问几道Pascal题目1、求一个三位数,其各位数的立方和,等于该数.2、求1!+2!+3!+4!+……+10!的值.
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/05 20:35:47
问几道Pascal题目1、求一个三位数,其各位数的立方和,等于该数.2、求1!+2!+3!+4!+……+10!的值.
问几道Pascal题目
1、求一个三位数,其各位数的立方和,等于该数.
2、求1!+2!+3!+4!+……+10!的值.
问几道Pascal题目1、求一个三位数,其各位数的立方和,等于该数.2、求1!+2!+3!+4!+……+10!的值.
1、
program xiti;
var a,b,c,d,i:integer;
begin
for i:=1000 to 9999 do
begin
a:=i div 1000;
b:=i div 100 mod 10;
c:=i div 10 mod 10;
d:=i mod 10;
if a*a*a*a+b*b*b*b+c*c*c*c+d*d*d*d=i then
writeln(i:6);
end;
end.
2、program aa;
var ans,i:longint;
procedure work(n:longint);
var i,s:longint;
begin
s:=1;
for i:=1 to n do
s:=s*i;
ans:=ans+s;
end;
begin
ans:=0;
for i:=1 to 10 do work(i);
writeln(ans);
end.
没有调试过,你自己看看能不能吧……
program one;
var b,c,d,i,k:integer;
begin
k:=0;
for i:=100 to 999 do
begin
b:=i div 100;
c:=i div 10 mod 10;
d:=i mod 10;
if b*b*b+c*c*c+d*d*...
全部展开
program one;
var b,c,d,i,k:integer;
begin
k:=0;
for i:=100 to 999 do
begin
b:=i div 100;
c:=i div 10 mod 10;
d:=i mod 10;
if b*b*b+c*c*c+d*d*d=i then
begin
k:=k+1;
write(i,' ');
if k mod 20=0 then writeln;
end;
end;
end.
楼上的第二题效率太低。。。发一个我的:
program two;
const n=10;
var ans:longint;
i:shortint;
begin
ans:=n;
for i:=n-1 downto 1 do
ans:=(ans+1)*i;
writeln(ans);
end.
收起
1、
var i,j,k:longint;
begin
for i:=1 to 9 do
for j:=0 to 9 do
for k:=0 to 9 do
if i*i*i+j*j*j+k*k*k=i*100+j*10+k then write(i,j,k,' ');
end.
2、
全部展开
1、
var i,j,k:longint;
begin
for i:=1 to 9 do
for j:=0 to 9 do
for k:=0 to 9 do
if i*i*i+j*j*j+k*k*k=i*100+j*10+k then write(i,j,k,' ');
end.
2、
var a,b,c:array[1..5000]of longint;
w,w1,w2,i,n,j:longint;
procedure as;
var i,x:longint;
begin
x:=0;
if w>w1 then w2:=w
else w2:=w1;
for i:=1 to w2 do
begin
c[i]:=a[i]+b[i]+x;
x:=c[i] div 10;
c[i]:=c[i] mod 10;
end;
while x>0 do begin
inc(w2);
c[w2]:=x mod 10;
x:=x div 10;
end;
end;
procedure asd(k:longint);
var i,x:longint;
begin
x:=0;
for i:=1 to w do begin
a[i]:=a[i]*k+x;
x:=a[i] div 10;
a[i]:=a[i] mod 10;
end;
while x>0 do begin
inc(w);
a[w]:=x mod 10;
x:=x div 10;
end;
end;
begin
readln(n);
w:=1;
a[1]:=1;
w1:=1;
b[1]:=2;
for i:=3 to n do begin
as;
b:=c;
w:=1;
a[1]:=1;
for j:=1 to i do asd(j);
end;
as;
for i:=w2 downto 1 do write(c[i]);
end.
收起
1、
var i,j,k:longint;
begin
for i:=1 to 9 do
for j:=0 to 9 do
for k:=0 to 9 do
if i*i*i+j*j*j+k*k*k=i*100+j*10+k then write(i,j,k,' ');
end.
2、
全部展开
1、
var i,j,k:longint;
begin
for i:=1 to 9 do
for j:=0 to 9 do
for k:=0 to 9 do
if i*i*i+j*j*j+k*k*k=i*100+j*10+k then write(i,j,k,' ');
end.
2、
var a,b,c:array[1..5000]of longint;
w,w1,w2,i,n,j:longint;
procedure as;
var i,x:longint;
begin
x:=0;
if w>w1 then w2:=w
else w2:=w1;
for i:=1 to w2 do
begin
c[i]:=a[i]+b[i]+x;
x:=c[i] div 10;
c[i]:=c[i] mod 10;
end;
while x>0 do begin
inc(w2);
c[w2]:=x mod 10;
x:=x div 10;
end;
end;
procedure asd(k:longint);
var i,x:longint;
begin
x:=0;
for i:=1 to w do begin
a[i]:=a[i]*k+x;
x:=a[i] div 10;
a[i]:=a[i] mod 10;
end;
while x>0 do begin
inc(w);
a[w]:=x mod 10;
x:=x div 10;
end;
end;
begin
readln(n);
w:=1;
a[1]:=1;
w1:=1;
b[1]:=2;
for i:=3 to n do begin
as;
b:=c;
w:=1;
a[1]:=1;
for j:=1 to i do asd(j);
end;
as;
for i:=w2 downto 1 do write(c[i]);
end.
不敢保证百分百正确,但敢保证百分之95以上
收起