主题:pascal题目,求大侠,要用for语句
qingtianzhu
[专家分:0] 发布于 2007-10-07 18:57:00
2.有一数列:第一项是0,第二项是1,第三项起是前二项的和,0,1,1,2,3,5,8,13,21,…。输出前31项的值。
3.寻找四位的平方数,例:2500=50*50。(每行打印10个)
6.蜘蛛有8条腿,蜻蜓有6条腿和2对翅,蝉有6条腿和1对翅.三种虫子共18只,共有118条腿和20对翅.问每虫子各几只?
(1) 1兔换2鸡,2兔换3鸭,5兔换7鹅.某人用20只兔换得鸡,鸭,鹅共30只.问其中鸡,鸭,鹅各几只?
(2)打印以下三角形:从键盘输入一个自然数N(1≤N≤9),根据N的值,打印输出对应的三角形,
例如:N = 4
输出: A
A B A
A B C B A
A B C D C B A
A B C B A
A B A
A
(3)求所有满足下述条件的四位数abcd:
① 四位数是11的倍数;
②a,b,c,d互不相同;
③b+c=a;
④bc是完全平方数(如b=2,c=5,则bc为25,是完全平方数)
回复列表 (共11个回复)
沙发
gundamoo [专家分:10] 发布于 2007-10-12 18:15:00
2. var a:array[1..31] of integer;
i:integer;
begin
a[1]:=0;
a[2]:=0;
write(a[1]:3); write(a[2]:3);
for i:=3 to 31 do
begin
a[i]:=a[i-1]+a[i-2];
write(a[i]:3);
end;
end.
板凳
gundamoo [专家分:10] 发布于 2007-10-12 18:19:00
3.var
i,n:integer;
begin
for i:=32 to 99 do
begin
n:=i*i;
write(n);
end;
end.
3 楼
gundamoo [专家分:10] 发布于 2007-10-12 18:25:00
6.var
i,j:integer;
begin
for i:=1 to 18 do
for j:=1 to 18-i do
if (8*i+6*j+6*(18-i-j)=118) and (2*k+18-i-j=20) then
write(i,j,18-i-j);
end.
4 楼
gundamoo [专家分:10] 发布于 2007-10-12 18:34:00
(2).var
i,j,k:integer;
begin
for i:=1 to 20 do
for j:=1 to 10 do
for k:=1 to 4 do
if (i+2*j+5*k=20) and (2*i+3*j+7*k=30) then
write(i,j,k);
end.
5 楼
gundamoo [专家分:10] 发布于 2007-10-12 19:04:00
(3).var
a:array[1..100] of char;
i,j,n:integer;
begin
readln(n);
for i:=1 to n do
begin
for j:=1 to 20-i do
write(' ');
for j:=0 to i-1 do
begin
a[j]:=chr(ord('A')+j);
write(a[j]);
end;
writeln;
end;
for i:=n-1 downto 1 do
begin
for j:=1 to 20-i do
write(' ');
for j:=0 to i-1 do
begin
a[j]:=chr(ord('A')+j);
write(a[j]);
end;
writeln;
end;
end.
6 楼
gundamoo [专家分:10] 发布于 2007-10-12 19:20:00
(4).var
a,b,c,d:integer;
begin
for a:=1 to 9 do
for b:=1 to 9 do
for c:=1 to 9 do
for d:=1 to 9 do
if (a<>b) and (a<>c) and (a<>d) and (b<>c) and (b<>d) and (c<>d) then
if b+c=a then
if (1000*a+100*b+10*c+d) mod 11=0 then
if trunk(sqrt(10*b+a))*trunk(sqrt(10*b+a))=10*b+c then
write(1000*a+100*b+10*c+d);
end.
7 楼
abcwuhang [专家分:1840] 发布于 2007-10-14 14:09:00
先从条件4入手(因为平方数只有6个(范围:10到99之间)),枚举平方数,拆开b和c,则由条件3得a=b+c.再枚举d即可
8 楼
abcwuhang [专家分:1840] 发布于 2007-10-14 14:09:00
时间:O(1)
9 楼
yxok200 [专家分:10] 发布于 2007-12-24 16:49:00
2.var b:array[1..31] of longint;
i:integer;
begin
b[1]:=0;
b[2]:=1;
write(b[1],' '); write(b[2],' ');
for i:=3 to 31 do
begin
b[i]:=b[i-1]+b[i-2];
write(b[i],' ');
end;
readln;
end.
10 楼
yxok200 [专家分:10] 发布于 2007-12-24 17:02:00
var
i,n:integer;
begin
for i:=33 to 99 do
begin;
write(sqr(i),' ');
if i=33 then write else
if (i-32) mod 10=0 then writeln;
end;
readln;
end.
我来回复