January 24, 2014

Computation of perfect numbers from 1 to 10000.

The program calculates and displays all perfect numbers in the range from 1 to 10000.
Programming language: FreePascal.

Code:
program perfectnumbers;
Uses crt;

var
j, i, h:longint;

begin
  ClrScr;

  for i:=6 to 10000 do
  begin
  h:=1;
  for j:=2 to i-1 do
  begin

   if (i mod j)=0 then
   begin
    h:=h+j;
   end;
  end;

  if h=i then
  Writeln('Perfect =  ',i)
  end;
end.

No comments:

Post a Comment