pascal语言中,用三种循环程序找出100至999的水仙花数(如153=1*1*1+5*5*5+3*3*3)

来源:百度知道 编辑:UC知道 时间:2024/05/03 02:29:13

Program e;
Var
i, j, k, x, y: Integer;
Begin
For i:=1 to 9 Do
For j:=0 to 9 Do
For k:=0 to 9 Do Begin
x := i * i * i + j * j * j + k * k * k;
y := i * 100 + j * 10 + k;
If x = y Then Write(i, j, k, ' ');
End;
End.
While 和 Repeat循环只要改循环变量的方式就可以了

program sxh;
var a,b,c,d:integer;
begin
for a:=100 to 999 do begin
b:=a mod 10;
c:=a mod 100 div 10;
d:=a div 100;
if b*b*b+c*c*c+d*d*d=a then writeln(a);
end;
end.