my code prints “6 24 24 24 24 28 496”. i don’t want the 24s. how can i solve this problem?
program perfect;
uses crt;
var i,number,temp:integer;
begin
clrscr;
for number:=2 to 999 do begin
temp:=1;
for i:=2 to Trunc(number/2) do begin
if (number mod i = 0) then
temp:=temp+i;
if(temp=number) then
writeln(number);
end;
end;
readln;
end.
You should move the if statement.
The code should be:
In that form it works fine(I got 6,28 and 496)