0 bình luận về “Viết chương trình tìm số hoàn hảo bé hơn 100”
var i, x, max, sum : longint; var perfecti : boolean; begin max := 100; for i := 1 to max do begin sum := 0; for x := 1 to i-1 do if i mod x = 0 then sum := sum + x; perfecti := sum = i; if perfecti then writeln(i, ‘ ‘, perfecti); end; readln(); end.
var i, x, max, sum : longint;
var perfecti : boolean;
begin
max := 100;
for i := 1 to max do
begin
sum := 0;
for x := 1 to i-1 do
if i mod x = 0 then
sum := sum + x;
perfecti := sum = i;
if perfecti then
writeln(i, ‘ ‘, perfecti);
end;
readln();
end.
program so_hoan_hao;
uses crt;
var n,i,j,t:integer;
begin
clrscr;
write(‘Cac so hoan hao be hon 100 la: ‘);
for i:=2 to 100 do
begin
t:=0;
for j:=1 to i div 2 do
if i mod j=0 then t:=t+j;
if t=i then write(i,’ ‘);
end;
readln;
end.