Подпрограммы. Дано натуральное число n. Дано натуральное число n. Выяснить, можно ли представить n в виде произведения трех последовательных натуральных чисел. В программе должна быть подпрограмма и написана на Pascal
program ThreeConsecutiveNumbers; function IsProductOfThreeConsecutiveNumbers(n: Integer): Boolean; begin if (Trunc(Sqrt(n)) * (Trunc(Sqrt(n)) + 1) * (Trunc(Sqrt(n)) + 2) = n) then IsProductOfThreeConsecutiveNumbers := True else IsProductOfThreeConsecutiveNumbers := False; end; var n: Integer; begin writeln('Enter a natural number:'); readln(n); if IsProductOfThreeConsecutiveNumbers(n) then writeln(n, ' can be represented as the product of three consecutive natural numbers.') else writeln(n, ' cannot be represented as the product of three consecutive natural numbers.'); end.
function IsProductOfThreeConsecutiveNumbers(n: Integer): Boolean;
begin
if (Trunc(Sqrt(n)) * (Trunc(Sqrt(n)) + 1) * (Trunc(Sqrt(n)) + 2) = n) then
IsProductOfThreeConsecutiveNumbers := True
else
IsProductOfThreeConsecutiveNumbers := False;
end;
var
n: Integer;
begin
writeln('Enter a natural number:');
readln(n);
if IsProductOfThreeConsecutiveNumbers(n) then
writeln(n, ' can be represented as the product of three consecutive natural numbers.')
else
writeln(n, ' cannot be represented as the product of three consecutive natural numbers.');
end.