水仙花数 Pascal 语言用repeat语句编写

3位数的 。。速度还有while 语句 谢谢啦
2024-12-16 23:46:10
推荐回答(3个)
回答1:

repeat解:
var count,a,b,c:integer;
begin
repeat
inc(count);
a:=count div 100;
b:=count div 10-a*10;
c:=count-a*100-b*10;
if a*a*a+b*b*b+c*c*c=count then writeln(count);
until count=999;
end.
while解自己改吧

回答2:

while解:var count,a,b,c:integer;
begin
conut:=0;
while count<=999 do begin inc(count); a:=count div 100; b:=count div 10-a*10; c:=count-a*100-b*10; if a*a*a+b*b*b+c*c*c=count then writeln(count); end;
end.

(while后接的是单语句,先判断后执行..还要注意数据初始化)

回答3:

var a,b,c:integer;
begin
for a:=1 to 9 do
for b:=0 to 9 do
for c:=0 to 9 do
if a*a*a+b*b*b+c*c*c=100*a+10*b+c then writeln(a,b,c);
end.
这是最简单的
用REPEAT?比较恶心,加点分我帮你做