Определите, является ли число N простым. (паскаль)

Ответы

Ответ дал: Giammy
0

PascalABC.NET 3.4.2, сборка 1843 от 24.10.2018

function IsPrime(self: integer): boolean; extensionmethod;

begin

Result := true;

 if self <= 1 then begin Result := false; exit; end;

for var i := 2 to floor(sqrt(self)) do

 if self mod i = 0 then begin result := false; exit; end;

end;


begin

Println(ReadInteger.IsPrime ? 'Да' : 'Нет')

end.

Вас заинтересует