Viết chương trình sử dụng lệnh lặp for…do tìm các số hoàn hảo nhỏ hơn 1000, số hoàn hảo là những số bằng tổng các ước thực sự của nó. Nhanh lên các bạn mik cần gấp

2 câu trả lời

Program FNG;
Uses crt;
Var i,s: longint;

Function shh(a: longint): boolean;
Var s: longint;
Begin
        s:=0;
        For i:=1 to a div 2 do
                If a mod i = 0 then s:=s+i;
        If a=s then exit(true);
        exit(false);
End;

Begin
        For i:=1 to 1000 do
                If shh(i) then Write(i,' ');
        Readln
End.

Uses crt;
Var i,s: longint;
Function shh(a: longint): boolean;
Var s: longint;
Begin
        s:=0;
        For i:=1 to a-1 do
                If a mod i = 0 then s:=s+i;
        If a=s then exit(true);
        exit(false);
End;

Begin
        For i:=1 to 1000-1 do
                If shh(i) then Write(i,' ');
        Readln
End.